From 36a6f9a09b966922baf4838599e57250982b0fc3 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 11 Apr 2019 15:15:20 +0200 Subject: Abstract get_type() into a trait --- dhall/src/typecheck.rs | 54 ++++++++++---------------------------------------- 1 file changed, 10 insertions(+), 44 deletions(-) (limited to 'dhall/src/typecheck.rs') diff --git a/dhall/src/typecheck.rs b/dhall/src/typecheck.rs index 0ddb784..3350964 100644 --- a/dhall/src/typecheck.rs +++ b/dhall/src/typecheck.rs @@ -1,7 +1,9 @@ #![allow(non_snake_case)] +use std::borrow::Borrow; use std::fmt; use crate::expr::*; +use crate::traits::DynamicType; use dhall_core; use dhall_core::context::Context; use dhall_core::*; @@ -24,19 +26,6 @@ impl Resolved { } } impl Typed { - fn as_expr(&self) -> &SubExpr { - &self.0 - } - fn into_expr(self) -> SubExpr { - self.0 - } - pub fn get_type(&self) -> Result<&Type, TypeError> { - self.1.as_ref().ok_or(TypeError::new( - &Context::new(), - self.0.clone(), - TypeMessage::Untyped, - )) - } fn get_type_move(self) -> Result> { self.1.ok_or(TypeError::new( &Context::new(), @@ -46,22 +35,6 @@ impl Typed { } } impl Normalized { - fn as_expr(&self) -> &SubExpr { - &self.0 - } - pub(crate) fn into_expr(self) -> SubExpr { - self.0 - } - pub fn get_type(&self) -> Result<&Type, TypeError> { - self.1.as_ref().ok_or(TypeError::new( - &Context::new(), - self.0.clone(), - TypeMessage::Untyped, - )) - } - pub(crate) fn into_type(self) -> Type { - crate::expr::Type(TypeInternal::Expr(Box::new(self))) - } // Expose the outermost constructor fn unroll_ref(&self) -> &Expr { self.as_expr().as_ref() @@ -98,17 +71,6 @@ impl Type { fn unroll_ref(&self) -> Result<&Expr, TypeError> { Ok(self.as_normalized()?.unroll_ref()) } - pub fn get_type(&self) -> Result<&Type, TypeError> { - use TypeInternal::*; - match &self.0 { - Expr(e) => e.get_type(), - SuperType => Err(TypeError::new( - &Context::new(), - rc(ExprF::Const(Const::Sort)), - TypeMessage::Untyped, - )), - } - } fn shift(&self, delta: isize, var: &V