diff options
author | Fintan Halpenny | 2019-09-06 12:43:52 +0200 |
---|---|---|
committer | Fintan Halpenny | 2019-09-06 12:43:52 +0200 |
commit | 4424d3ece5db10527ae446a685a579ae768ef943 (patch) | |
tree | 688d29c25f12c2c5347e3d24db8b9b7fb83c7b04 /dhall/src/core | |
parent | 52c91e08db68e05f760ebfd465b84fe4107731df (diff) | |
parent | bcaeab3b7b114d8782be9589ad673ab9ab8c59fd (diff) |
Merge remote-tracking branch 'origin/master' into fintan/canonicalize
Diffstat (limited to 'dhall/src/core')
-rw-r--r-- | dhall/src/core/value.rs | 11 | ||||
-rw-r--r-- | dhall/src/core/valuef.rs | 27 | ||||
-rw-r--r-- | dhall/src/core/var.rs | 12 |
3 files changed, 9 insertions, 41 deletions
diff --git a/dhall/src/core/value.rs b/dhall/src/core/value.rs index 3cccb1d..b4b6b08 100644 --- a/dhall/src/core/value.rs +++ b/dhall/src/core/value.rs @@ -212,17 +212,6 @@ impl Value { WHNF | NF => {} } } - pub(crate) fn normalize_nf(&self) { - let borrow = self.as_internal(); - match borrow.form { - Unevaled | WHNF => { - drop(borrow); - self.as_internal_mut().normalize_nf(); - } - // Already in NF - NF => {} - } - } pub(crate) fn app(&self, v: Value) -> Value { let body_t = match &*self.get_type_not_sort().as_whnf() { diff --git a/dhall/src/core/valuef.rs b/dhall/src/core/valuef.rs index 7ecec86..4e457e6 100644 --- a/dhall/src/core/valuef.rs +++ b/dhall/src/core/valuef.rs @@ -110,17 +110,11 @@ impl ValueF { ValueF::UnionConstructor(l.clone(), kts.clone()).to_expr(opts), v.to_expr(opts), )), - ValueF::TextLit(elts) => { - use InterpolatedTextContents::{Expr, Text}; - rc(ExprF::TextLit( - elts.iter() - .map(|contents| match contents { - Expr(e) => Expr(e.to_expr(opts)), - Text(s) => Text(s.clone()), - }) - .collect(), - )) - } + ValueF::TextLit(elts) => rc(ExprF::TextLit( + elts.iter() + .map(|contents| contents.map_ref(|e| e.to_expr(opts))) + .collect(), + )), ValueF::Equivalence(x, y) => rc(ExprF::BinOp( dhall_syntax::BinOp::Equivalence, x.to_expr(opts), @@ -187,11 +181,7 @@ impl ValueF { } ValueF::TextLit(elts) => { for x in elts.iter_mut() { - use InterpolatedTextContents::{Expr, Text}; - match x { - Expr(n) => n.normalize_mut(), - Text(_) => {} - } + x.map_mut(Value::normalize_mut); } } ValueF::Equivalence(x, y) => { @@ -199,10 +189,7 @@ impl ValueF { y.normalize_mut(); } ValueF::PartialExpr(e) => { - // TODO: need map_mut - e.map_ref(|v| { - v.normalize_nf(); - }); + e.map_mut(Value::normalize_mut); } } } diff --git a/dhall/src/core/var.rs b/dhall/src/core/var.rs index ce4d137..3795f10 100644 --- a/dhall/src/core/var.rs +++ b/dhall/src/core/var.rs @@ -224,11 +224,7 @@ where impl<T: Shift> Shift for dhall_syntax::InterpolatedTextContents<T> { fn shift(&self, delta: isize, var: &AlphaVar) -> Option<Self> { - use dhall_syntax::InterpolatedTextContents::{Expr, Text}; - Some(match self { - Expr(x) => Expr(x.shift(delta, var)?), - Text(s) => Text(s.clone()), - }) + Some(self.traverse_ref(|x| Ok(x.shift(delta, var)?))?) } } @@ -283,11 +279,7 @@ impl<S, T: Subst<S>> Subst<S> for Vec<T> { impl<S, T: Subst<S>> Subst<S> for dhall_syntax::InterpolatedTextContents<T> { fn subst_shift(&self, var: &AlphaVar, val: &S) -> Self { - use dhall_syntax::InterpolatedTextContents::{Expr, Text}; - match self { - Expr(x) => Expr(x.subst_shift(var, val)), - Text(s) => Text(s.clone()), - } + self.map_ref(|x| x.subst_shift(var, val)) } } |