From bbf8d68b0df3ca8b3b8cb7324169f0049736ed89 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sat, 20 Apr 2019 23:52:09 +0200 Subject: Move TypeInternal to typecheck --- dhall/src/expr.rs | 16 ++-------------- dhall/src/typecheck.rs | 38 +++++++++++++++++++++++++++++--------- 2 files changed, 31 insertions(+), 23 deletions(-) (limited to 'dhall') diff --git a/dhall/src/expr.rs b/dhall/src/expr.rs index bb1a4e4..03aa966 100644 --- a/dhall/src/expr.rs +++ b/dhall/src/expr.rs @@ -63,6 +63,8 @@ pub struct SimpleType<'a>( ); derive_other_traits!(SimpleType); +pub(crate) use crate::typecheck::TypeInternal; + /// A Dhall expression representing a (possibly higher-kinded) type. /// /// This includes [SimpleType]s but also higher-kinded expressions like @@ -70,14 +72,6 @@ derive_other_traits!(SimpleType); #[derive(Debug, Clone, PartialEq, Eq)] pub struct Type<'a>(pub(crate) TypeInternal<'a>); -#[derive(Debug, Clone, PartialEq, Eq)] -pub(crate) enum TypeInternal<'a> { - Expr(Box>), - Const(dhall_core::Const), - /// The type of `Sort` - SuperType, -} - // Exposed for the macros #[doc(hidden)] impl<'a> From> for SubExpr { @@ -120,12 +114,6 @@ impl<'a> Normalized<'a> { pub(crate) fn unnote<'b>(self) -> Normalized<'b> { Normalized(self.0, self.1, PhantomData) } - pub(crate) fn into_type(self) -> Type<'a> { - Type(match self.0.as_ref() { - ExprF::Const(c) => TypeInternal::Const(*c), - _ => TypeInternal::Expr(Box::new(self)), - }) - } } #[doc(hidden)] diff --git a/dhall/src/typecheck.rs b/dhall/src/typecheck.rs index b26f845..99fb003 100644 --- a/dhall/src/typecheck.rs +++ b/dhall/src/typecheck.rs @@ -48,6 +48,12 @@ impl<'a> Normalized<'a> { // shift the type too ? Normalized(shift0(delta, label, &self.0), self.1.clone(), self.2) } + pub(crate) fn into_type(self) -> Type<'a> { + Type(match self.0.as_ref() { + ExprF::Const(c) => TypeInternal::Const(*c), + _ => TypeInternal::Expr(Box::new(self)), + }) + } } impl Normalized<'static> { fn embed(self) -> SubExpr> { @@ -69,15 +75,7 @@ impl<'a> Type<'a> { } } pub(crate) fn into_normalized(self) -> Result, TypeError> { - match self.0 { - TypeInternal::Expr(e) => Ok(*e), - TypeInternal::Const(c) => Ok(const_to_normalized(c)), - TypeInternal::SuperType => Err(TypeError::new( - &Context::new(), - rc(ExprF::Const(Const::Sort)), - TypeMessage::Untyped, - )), - } + self.0.into_normalized() } // Expose the outermost constructor fn unroll_ref(&self) -> Result>, TypeError> { @@ -111,6 +109,28 @@ impl Type<'static> { } } +#[derive(Debug, Clone, PartialEq, Eq)] +pub(crate) enum TypeInternal<'a> { + Expr(Box>), + Const(dhall_core::Const), + /// The type of `Sort` + SuperType, +} + +impl<'a> TypeInternal<'a> { + fn into_normalized(self) -> Result, TypeError> { + match self { + TypeInternal::Expr(e) => Ok(*e), + TypeInternal::Const(c) => Ok(const_to_normalized(c)), + TypeInternal::SuperType => Err(TypeError::new( + &Context::new(), + rc(ExprF::Const(Const::Sort)), + TypeMessage::Untyped, + )), + } + } +} + fn function_check(a: Const, b: Const) -> Result { use dhall_core::Const::*; match (a, b) { -- cgit v1.2.3