#![allow(non_snake_case)] use std::fmt; use crate::expr::*; use dhall_core; use dhall_core::context::Context; use dhall_core::*; use dhall_generator as dhall; use std::borrow::Cow; use self::TypeMessage::*; impl Resolved { pub fn typecheck(self) -> Result> { let typ = crate::typecheck::type_of_(self.0.clone())?; Ok(typ) } } impl Typed { fn as_expr(&self) -> &SubExpr { &self.0 } fn into_expr(self) -> SubExpr { self.0 } pub fn get_type<'a>(&'a self) -> Type<'a> { self.1.reborrow() } } impl Normalized { fn as_expr(&self) -> &SubExpr { &self.0 } fn into_expr(self) -> SubExpr { self.0 } pub fn get_type<'a>(&'a self) -> Type<'a> { self.1.reborrow() } fn into_type(self) -> Type<'static> { crate::expr::Type(Cow::Owned(TypeInternal::Expr(Box::new(self)))) } } impl<'a> Type<'a> { fn into_owned(self) -> Type<'static> { Type(Cow::Owned(self.0.into_owned())) } fn reborrow<'b>(&'b self) -> Type<'b> { match &self.0 { Cow::Owned(x) => crate::expr::Type(Cow::Borrowed(x)), Cow::Borrowed(x) => crate::expr::Type(Cow::Borrowed(x)), } } fn as_expr(&'a self) -> &'a SubExpr { use TypeInternal::*; match self.0.as_ref() { Expr(e) => e.as_expr(), Universe(_) => unimplemented!(), } } fn into_expr(self) -> SubExpr { use TypeInternal::*; match self.0.into_owned() { Expr(e) => e.into_expr(), Universe(_) => unimplemented!(), } } pub fn get_type<'b>(&'b self) -> Type<'b> { use TypeInternal::*; match self.0.as_ref() { Expr(e) => e.get_type(), Universe(n) => crate::expr::Type(Cow::Owned(Universe(n + 1))), } } } const TYPE_OF_SORT: Type<'static> = Type(Cow::Owned(TypeInternal::Universe(4))); fn rule(a: Const, b: Const) -> Result { use dhall_core::Const::*; match (a, b) { (_, Type) => Ok(Type), (Kind, Kind) => Ok(Kind), (Sort, Sort) => Ok(Sort), (Sort, Kind) => Ok(Sort), _ => Err(()), } } fn match_vars(vl: &V