From 843d895f2b1e28e9c8775a9d421c6618af98a4e5 Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 18 May 2018 01:43:51 -0700 Subject: [PATCH] infer infra --- schala-lang/src/typechecking.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/schala-lang/src/typechecking.rs b/schala-lang/src/typechecking.rs index 4c1e56e..3e2abc2 100644 --- a/schala-lang/src/typechecking.rs +++ b/schala-lang/src/typechecking.rs @@ -283,6 +283,8 @@ enum InferError { UnknownIdentifier(Rc) } +type InferResult = Result; + impl Infer { fn fresh(&mut self) -> MonoType { let i = self._idents; @@ -291,7 +293,7 @@ impl Infer { MonoType::Var(name) } - fn unify(&mut self, a: MonoType, b: MonoType) -> Result { + fn unify(&mut self, a: MonoType, b: MonoType) -> InferResult { use self::InferError::*; use self::MonoType::*; Ok(match (a, b) { (Const(ref a), Const(ref b)) if a == b => Substitution::new(), @@ -306,7 +308,7 @@ impl Infer { }) } - fn infer_block(&mut self, block: &Vec, env: &TypeEnvironment) -> Result { + fn infer_block(&mut self, block: &Vec, env: &TypeEnvironment) -> InferResult { use self::parsing::Statement; let mut ret = MonoType::Const(TypeConst::Unit); for statement in block.iter() { @@ -323,7 +325,24 @@ impl Infer { Ok(ret) } - fn infer_expr(&mut self, expr: &parsing::Expression, env: &TypeEnvironment) -> Result<(Substitution, MonoType), InferError> { + fn infer_expr(&mut self, expr: &parsing::Expression, env: &TypeEnvironment) -> InferResult<(Substitution, MonoType)> { + use self::parsing::Expression; + match expr { + Expression(e, Some(anno)) => self.infer_annotated_expr(e, anno, env), + /* + let anno_ty = anno.to_type()?; + let ty = self.infer_exprtype(&e)?; + self.unify(ty, anno_ty) + }, + */ + Expression(e, None) => self.infer_exprtype(e, env) + } + } + + fn infer_exprtype(&mut self, expr: &parsing::ExpressionType, env: &TypeEnvironment) -> InferResult<(Substitution, MonoType)> { + unimplemented!() + } + fn infer_annotated_expr(&mut self, expr: &parsing::ExpressionType, anno: &parsing::TypeName, env: &TypeEnvironment) -> InferResult<(Substitution, MonoType)> { unimplemented!() } }