From afd9aa52c5e14f40bba841a6d641c24770e3ba2a Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 10 Feb 2019 06:53:11 -0800 Subject: [PATCH] More infra around unify --- schala-lang/language/src/typechecking.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/schala-lang/language/src/typechecking.rs b/schala-lang/language/src/typechecking.rs index c392086..c457964 100644 --- a/schala-lang/language/src/typechecking.rs +++ b/schala-lang/language/src/typechecking.rs @@ -22,13 +22,13 @@ impl TypeError { } } -#[derive(Debug)] +#[derive(Debug, Clone)] pub enum Type { Const(TypeConst), Arrow(Box, Box) } -#[derive(Debug)] +#[derive(Debug, Clone)] pub enum TypeConst { Unit, Nat, @@ -150,6 +150,10 @@ impl<'a> TypeContext<'a> { } } + fn get_type_from_name(&self, name: &TypeIdentifier) -> InferResult { + Ok(Type::Const(TypeConst::Unit)) + } + pub fn typecheck(&mut self, ast: &AST) -> Result { let mut returned_type = Type::Const(TypeConst::Unit); for statement in ast.0.iter() { @@ -171,9 +175,11 @@ impl<'a> TypeContext<'a> { fn typecheck_expr(&mut self, expr: &Expression) -> InferResult { match expr { - Expression(expr_type, Some(_anno)) => { + Expression(expr_type, Some(anno)) => { //TODO here - self.typecheck_expr_type(expr_type) + let t1 = self.typecheck_expr_type(expr_type)?; + let t2 = self.get_type_from_name(anno)?; + self.unify(t2, t1) }, Expression(expr_type, None) => self.typecheck_expr_type(expr_type) } @@ -191,7 +197,8 @@ impl<'a> TypeContext<'a> { } - fn unify(&mut self, t1: &Type, t2: &Type) -> InferResult { - unimplemented!() + fn unify(&mut self, t1: Type, t2: Type) -> InferResult { + println!("Unify ain't done yo"); + Ok(t1) } }