From 366bc783e62682c9597e8caba1dac56638d34fa9 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sat, 6 Apr 2019 18:24:49 +0200 Subject: Define some newtypes for Expr Closes #50 --- dhall/src/expr.rs | 35 +++++++++++++++++++++++++++++++++++ dhall/src/lib.rs | 10 ++-------- 2 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 dhall/src/expr.rs 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); +pub struct Resolved(SubExpr); +pub struct Typed(SubExpr, Type); +pub struct Type(Box); +pub struct Normalized(SubExpr); + +// impl Parsed { +// pub fn resolve(self) -> Result { +// Ok(Resolved(crate::imports::resolve(self.0)?)) +// } +// } +impl Resolved { + pub fn typecheck(self) -> Result> { + 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::*; -- cgit v1.2.3