From 4cd6c39d6d61c1d5a2670fe52c79bce4f11facdb Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 12 Mar 2019 00:14:50 +0100 Subject: Handle Some and None builtins Closes #19 --- dhall/src/normalize.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'dhall/src') diff --git a/dhall/src/normalize.rs b/dhall/src/normalize.rs index 8948443..50a1625 100644 --- a/dhall/src/normalize.rs +++ b/dhall/src/normalize.rs @@ -36,6 +36,8 @@ where normalize_whnf(&b3) } (Builtin(b), a) => match (b, normalize_whnf(a)) { + (OptionalSome, a) => OptionalLit(None, vec![a]), + (OptionalNone, a) => OptionalLit(Some(bx(a)), vec![]), (NaturalIsZero, NaturalLit(n)) => BoolLit(n == 0), (NaturalEven, NaturalLit(n)) => BoolLit(n % 2 == 0), (NaturalOdd, NaturalLit(n)) => BoolLit(n % 2 != 0), @@ -149,7 +151,7 @@ where ) => { let e2: Expr<_, _> = xs.into_iter().fold( (**nothing).clone(), - |y, _| { + |_, y| { let y = bx(y); dhall_expr!(just y) }, @@ -186,6 +188,13 @@ where BoolLit(false) => normalize_whnf(f), b2 => BoolIf(bx(b2), t.clone(), f.clone()), }, + OptionalLit(t, es) => { + if !es.is_empty() { + OptionalLit(None, es.clone()) + } else { + OptionalLit(t.clone(), es.clone()) + } + } BinOp(o, x, y) => match (o, normalize_whnf(&x), normalize_whnf(&y)) { (BoolAnd, BoolLit(x), BoolLit(y)) => BoolLit(x && y), (BoolOr, BoolLit(x), BoolLit(y)) => BoolLit(x || y), -- cgit v1.2.3