From 36bcec6c91d3192b5c84c96af96961ff6b79f0f0 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 9 May 2019 23:35:08 +0200 Subject: Merge Type and Typed --- dhall/src/phase/mod.rs | 69 ++++++++++---------------------------------------- 1 file changed, 14 insertions(+), 55 deletions(-) (limited to 'dhall/src/phase/mod.rs') diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs index 3d7afb6..63480c5 100644 --- a/dhall/src/phase/mod.rs +++ b/dhall/src/phase/mod.rs @@ -49,8 +49,7 @@ pub enum Typed { #[derive(Debug, Clone)] pub struct Normalized(Typed); -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct Type(Typed); +pub type Type = Typed; impl Parsed { pub fn parse_file(f: &Path) -> Result { @@ -119,7 +118,7 @@ impl Typed { Typed::Const(c) } pub fn from_value_untyped(v: Value) -> Self { - Typed::Untyped(Thunk::from_value(v)) + Typed::from_thunk_untyped(Thunk::from_value(v)) } pub fn from_normalized_expr_untyped(e: NormalizedSubExpr) -> Self { Typed::from_thunk_untyped(Thunk::from_normalized_expr(e)) @@ -148,8 +147,19 @@ impl Typed { pub fn to_type(&self) -> Type { self.clone().into_type() } + // Deprecated pub fn into_type(self) -> Type { - Type(self) + self + } + pub fn to_normalized(&self) -> Normalized { + self.clone().normalize() + } + pub fn as_const(&self) -> Option { + // TODO: avoid clone + match &self.to_value() { + Value::Const(c) => Some(*c), + _ => None, + } } pub fn normalize_mut(&mut self) { @@ -171,36 +181,6 @@ impl Typed { } } -impl Type { - // Deprecated - pub fn to_normalized(&self) -> Normalized { - self.0.clone().normalize() - } - pub fn to_expr(&self) -> NormalizedSubExpr { - self.0.to_expr() - } - pub fn to_value(&self) -> Value { - self.0.to_value() - } - pub fn to_typed(&self) -> Typed { - self.0.clone() - } - pub fn as_const(&self) -> Option { - // TODO: avoid clone - match &self.to_value() { - Value::Const(c) => Some(*c), - _ => None, - } - } - pub fn get_type(&self) -> Result, TypeError> { - self.0.get_type() - } - - pub fn from_const(c: Const) -> Self { - Type(Typed::from_const(c)) - } -} - impl Normalized { #[allow(dead_code)] pub fn to_expr(&self) -> NormalizedSubExpr { @@ -220,9 +200,6 @@ impl Normalized { pub fn into_typed(self) -> Typed { self.0 } - pub fn get_type(&self) -> Result, TypeError> { - self.0.get_type() - } } impl Shift for Typed { @@ -238,12 +215,6 @@ impl Shift for Typed { } } -impl Shift for Type { - fn shift(&self, delta: isize, var: &AlphaVar) -> Option { - Some(Type(self.0.shift(delta, var)?)) - } -} - impl Shift for Normalized { fn shift(&self, delta: isize, var: &AlphaVar) -> Option { Some(Normalized(self.0.shift(delta, var)?)) @@ -263,12 +234,6 @@ impl Subst for Typed { } } -impl Subst for Type { - fn subst_shift(&self, var: &AlphaVar, val: &Typed) -> Self { - Type(self.0.subst_shift(var, val)) - } -} - macro_rules! derive_traits_for_wrapper_struct { ($ty:ident) => { impl std::cmp::PartialEq for $ty { @@ -306,9 +271,3 @@ impl Display for Typed { self.to_expr().fmt(f) } } - -impl Display for Type { - fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { - self.to_normalized().fmt(f) - } -} -- cgit v1.2.3