From 83bc67d4572fe7961842f915d5559ee489e13dfd Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sat, 20 Apr 2019 23:12:25 +0200 Subject: An empty optional value is purely semantic --- dhall/src/binary.rs | 2 +- dhall/src/normalize.rs | 13 +++++-------- dhall/src/typecheck.rs | 8 +------- 3 files changed, 7 insertions(+), 16 deletions(-) (limited to 'dhall') 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 { } [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, -- cgit v1.2.3