#![allow(non_snake_case)] use std::collections::BTreeMap; use std::rc::Rc; use dhall_core::context::Context; use dhall_core::{ rc, Builtin, Const, ExprF, Integer, InterpolatedText, InterpolatedTextContents, Label, Natural, SubExpr, V, X, }; use dhall_generator as dhall; use crate::expr::{Normalized, PartiallyNormalized, Type, Typed}; type InputSubExpr = SubExpr>; type OutputSubExpr = SubExpr; impl<'a> Typed<'a> { /// 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<'a> { self.partially_normalize().normalize() } pub(crate) fn partially_normalize(self) -> PartiallyNormalized<'a> { PartiallyNormalized( normalize_whnf( NormalizationContext::from_typecheck_ctx(&self.2), self.0, ), self.1, self.3, ) } /// Pretends this expression is normalized. Use with care. #[allow(dead_code)] pub fn skip_normalize(self) -> Normalized<'a> { Normalized( self.0.unroll().squash_embed(|e| e.0.clone()), self.1, self.3, ) } } impl<'a> PartiallyNormalized<'a> { pub(crate) fn normalize(self) -> Normalized<'a> { Normalized(self.0.normalize_to_expr(), self.1, self.2) } pub(crate) fn shift(&self, delta: isize, var: &V