summaryrefslogtreecommitdiff
path: root/dhall/src
diff options
context:
space:
mode:
authorNadrieril2019-03-12 00:14:50 +0100
committerNadrieril2019-03-12 00:23:39 +0100
commit4cd6c39d6d61c1d5a2670fe52c79bce4f11facdb (patch)
tree6dc184feea444d901993d9f8f4956844e8122cda /dhall/src
parentf1f292f5b7ed12b5b8d4a568b9db6bdbbcb23d83 (diff)
Handle Some and None builtins
Closes #19
Diffstat (limited to 'dhall/src')
-rw-r--r--dhall/src/normalize.rs11
1 files changed, 10 insertions, 1 deletions
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),