summaryrefslogtreecommitdiff
path: root/dhall
diff options
context:
space:
mode:
authorNadrieril2019-04-06 18:24:49 +0200
committerNadrieril2019-04-06 18:24:49 +0200
commit366bc783e62682c9597e8caba1dac56638d34fa9 (patch)
treecf6aa89b0126cba5198fd9c4abf4d668caac8517 /dhall
parent42d0f8100462f8a17a3ba1b86664310cdb71dfdc (diff)
Define some newtypes for Expr
Closes #50
Diffstat (limited to 'dhall')
-rw-r--r--dhall/src/expr.rs35
-rw-r--r--dhall/src/lib.rs10
2 files changed, 37 insertions, 8 deletions
diff --git a/dhall/src/expr.rs b/dhall/src/expr.rs
new file mode 100644
index 0000000..0d093cb
--- /dev/null
+++ b/dhall/src/expr.rs
@@ -0,0 +1,35 @@
+use crate::typecheck::TypeError;
+use dhall_core::*;
+
+pub struct Parsed(SubExpr<X, Import>);
+pub struct Resolved(SubExpr<X, X>);
+pub struct Typed(SubExpr<X, X>, Type);
+pub struct Type(Box<Normalized>);
+pub struct Normalized(SubExpr<X, X>);
+
+// impl Parsed {
+// pub fn resolve(self) -> Result<Resolved, ImportError> {
+// Ok(Resolved(crate::imports::resolve(self.0)?))
+// }
+// }
+impl Resolved {
+ pub fn typecheck(self) -> Result<Typed, TypeError<X>> {
+ let typ = Type(Box::new(Normalized(crate::typecheck::type_of(
+ self.0.clone(),
+ )?)));
+ Ok(Typed(self.0, typ))
+ }
+}
+impl Typed {
+ pub fn normalize(self) -> Normalized {
+ Normalized(crate::normalize::normalize(self.0))
+ }
+ pub fn get_type(&self) -> &Type {
+ &self.1
+ }
+}
+impl Type {
+ pub fn as_expr(&self) -> &Normalized {
+ &*self.0
+ }
+}
diff --git a/dhall/src/lib.rs b/dhall/src/lib.rs
index 7439312..fee5ba8 100644
--- a/dhall/src/lib.rs
+++ b/dhall/src/lib.rs
@@ -18,11 +18,5 @@ pub use crate::traits::*;
pub use dhall_generator::expr;
pub use dhall_generator::subexpr;
pub use dhall_generator::StaticType;
-
-// pub struct DhallExpr(dhall_core::DhallExpr);
-
-// impl DhallExpr {
-// pub fn normalize(self) -> Self {
-// DhallExpr(crate::normalize::normalize(self.0))
-// }
-// }
+pub mod expr;
+pub use crate::expr::*;