summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNadrieril2019-05-09 16:56:17 +0200
committerNadrieril2019-05-09 16:56:17 +0200
commitbf74436781a1304a937fb31a50c5495223468087 (patch)
tree06df62ab914c39e3572e9729c9b1088eec549741
parent32051979778436ea02cb406551f126fe22ea1636 (diff)
Small utility SubExpr::from_builtin
Diffstat (limited to '')
-rw-r--r--dhall/src/phase/typecheck.rs12
-rw-r--r--dhall_syntax/src/core/expr.rs4
2 files changed, 7 insertions, 9 deletions
diff --git a/dhall/src/phase/typecheck.rs b/dhall/src/phase/typecheck.rs
index 2dc97bb..66f5b5b 100644
--- a/dhall/src/phase/typecheck.rs
+++ b/dhall/src/phase/typecheck.rs
@@ -328,10 +328,7 @@ pub(crate) fn mktype(
}
pub(crate) fn builtin_to_type(b: Builtin) -> Result<Type, TypeError> {
- mktype(
- &TypecheckContext::new(),
- SubExpr::from_expr_no_note(ExprF::Builtin(b)),
- )
+ mktype(&TypecheckContext::new(), SubExpr::from_builtin(b))
}
/// Intermediary return type
@@ -390,15 +387,12 @@ fn type_with(
return type_with(&ctx.insert_value(x, v.clone())?, e.clone());
}
OldOptionalLit(None, t) => {
- let none = SubExpr::from_expr_no_note(ExprF::Builtin(
- Builtin::OptionalNone,
- ));
+ let none = SubExpr::from_builtin(Builtin::OptionalNone);
let e = e.rewrap(App(none, t.clone()));
return type_with(ctx, e);
}
OldOptionalLit(Some(x), t) => {
- let optional =
- SubExpr::from_expr_no_note(ExprF::Builtin(Builtin::Optional));
+ let optional = SubExpr::from_builtin(Builtin::Optional);
let x = x.rewrap(SomeLit(x.clone()));
let t = t.rewrap(App(optional, t.clone()));
let e = e.rewrap(Annot(x, t));
diff --git a/dhall_syntax/src/core/expr.rs b/dhall_syntax/src/core/expr.rs
index 3b73d88..c509bae 100644
--- a/dhall_syntax/src/core/expr.rs
+++ b/dhall_syntax/src/core/expr.rs
@@ -338,6 +338,10 @@ impl<N, E> SubExpr<N, E> {
SubExpr(Rc::new((x, None)))
}
+ pub fn from_builtin(b: Builtin) -> Self {
+ SubExpr::from_expr_no_note(ExprF::Builtin(b))
+ }
+
pub fn rewrap<E2>(&self, x: Expr<N, E2>) -> SubExpr<N, E2>
where
N: Clone,