diff options
author | Nadrieril | 2019-04-20 23:12:25 +0200 |
---|---|---|
committer | Nadrieril | 2019-04-20 23:12:25 +0200 |
commit | 83bc67d4572fe7961842f915d5559ee489e13dfd (patch) | |
tree | d6bff16ce18dda443aa8b9a2fb31c31f0a502ec4 /dhall/src | |
parent | 5812a53cc9241703bd35586da0036dc170ab3721 (diff) |
An empty optional value is purely semantic
Diffstat (limited to 'dhall/src')
-rw-r--r-- | dhall/src/binary.rs | 2 | ||||
-rw-r--r-- | dhall/src/normalize.rs | 13 | ||||
-rw-r--r-- | dhall/src/typecheck.rs | 8 |
3 files changed, 7 insertions, 16 deletions
diff --git a/dhall/src/binary.rs b/dhall/src/binary.rs index 62ebcf7..7ded3a5 100644 --- a/dhall/src/binary.rs +++ b/dhall/src/binary.rs @@ -111,7 +111,7 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<ParsedExpr, DecodeError> { } [U64(5), Null, x] => { let x = cbor_value_to_dhall(&x)?; - NEOptionalLit(x) + SomeLit(x) } [U64(5), t, x] => { let x = cbor_value_to_dhall(&x)?; diff --git a/dhall/src/normalize.rs b/dhall/src/normalize.rs index 9e7c531..f092c4d 100644 --- a/dhall/src/normalize.rs +++ b/dhall/src/normalize.rs @@ -366,10 +366,12 @@ impl WHNF { WHNF::NaturalLit(n) => rc(ExprF::NaturalLit(n)), WHNF::IntegerLit(n) => rc(ExprF::IntegerLit(n)), WHNF::EmptyOptionalLit(n) => { - rc(ExprF::EmptyOptionalLit(n.normalize().normalize_to_expr())) + WHNF::Expr(rc(ExprF::Builtin(Builtin::OptionalNone))) + .app(n.normalize()) + .normalize_to_expr() } WHNF::NEOptionalLit(n) => { - rc(ExprF::NEOptionalLit(n.normalize().normalize_to_expr())) + rc(ExprF::SomeLit(n.normalize().normalize_to_expr())) } WHNF::EmptyListLit(n) => { rc(ExprF::EmptyListLit(n.normalize().normalize_to_expr())) @@ -628,12 +630,7 @@ fn normalize_whnf(ctx: NormalizationContext, expr: InputSubExpr) -> WHNF { ExprF::OldOptionalLit(Some(e), _) => { WHNF::NEOptionalLit(Now::new(ctx, e.clone())) } - ExprF::EmptyOptionalLit(e) => { - WHNF::EmptyOptionalLit(Now::new(ctx, e.clone())) - } - ExprF::NEOptionalLit(e) => { - WHNF::NEOptionalLit(Now::new(ctx, e.clone())) - } + ExprF::SomeLit(e) => WHNF::NEOptionalLit(Now::new(ctx, e.clone())), ExprF::EmptyListLit(e) => WHNF::EmptyListLit(Now::new(ctx, e.clone())), ExprF::NEListLit(elts) => WHNF::NEListLit( elts.iter() diff --git a/dhall/src/typecheck.rs b/dhall/src/typecheck.rs index ddb96da..b26f845 100644 --- a/dhall/src/typecheck.rs +++ b/dhall/src/typecheck.rs @@ -563,13 +563,7 @@ fn type_last_layer( let e = dhall::subexpr!(Some x : Optional t); Ok(RetType(type_with(ctx, e)?.get_type()?.into_owned())) } - EmptyOptionalLit(t) => { - let t = t.normalize(); - ensure_simple_type!(t, mkerr(InvalidOptionalType(t))); - let t = t.embed(); - Ok(RetExpr(dhall::expr!(Optional t))) - } - NEOptionalLit(x) => { + SomeLit(x) => { let tx = x.get_type_move()?; ensure_simple_type!( tx, |