#![allow(non_snake_case)] use std::collections::BTreeMap; use std::rc::Rc; use dhall_proc_macros as dhall; use dhall_syntax::context::Context; use dhall_syntax::{ rc, BinOp, Builtin, Const, ExprF, Integer, InterpolatedText, InterpolatedTextContents, Label, Natural, Span, SubExpr, V, X, }; use crate::expr::{Normalized, Type, Typed, TypedInternal}; type InputSubExpr = SubExpr; type OutputSubExpr = SubExpr; impl Typed { /// Reduce an expression to its normal form, performing beta reduction /// /// `normalize` does not type-check the expression. You may want to type-check /// expressions before normalizing them since normalization can convert an /// ill-typed expression into a well-typed expression. /// /// However, `normalize` will not fail if the expression is ill-typed and will /// leave ill-typed sub-expressions unevaluated. /// pub fn normalize(self) -> Normalized { match &self.0 { TypedInternal::Sort => {} TypedInternal::Value(thunk, _) => { thunk.normalize_nf(); } } Normalized(self.0) } pub(crate) fn shift(&self, delta: isize, var: &DoubleVar) -> Self { Typed(self.0.shift(delta, var)) } pub(crate) fn subst_shift(&self, var: &DoubleVar, val: &Typed) -> Self { Typed(self.0.subst_shift(var, val)) } pub(crate) fn to_value(&self) -> Value { self.0.to_value() } pub(crate) fn to_thunk(&self) -> Thunk { self.0.to_thunk() } } /// Stores a pair of variables: a normal one and if relevant one /// that corresponds to the alpha-normalized version of the first one. #[derive(Debug, Clone, Eq)] pub(crate) struct DoubleVar { normal: V