From 0cf56eea4f056bc04180b7869d652e0e0d775462 Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 11 Oct 2017 02:11:12 -0700 Subject: [PATCH] the evar table TODO find a better way to represent this --- src/schala_lang/type_check.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/schala_lang/type_check.rs b/src/schala_lang/type_check.rs index ed40dcf..fc1903a 100644 --- a/src/schala_lang/type_check.rs +++ b/src/schala_lang/type_check.rs @@ -62,6 +62,7 @@ struct TypeContextEntry { pub struct TypeContext { symbol_table: HashMap, + evar_table: HashMap, existential_type_label_count: u64 } @@ -69,6 +70,7 @@ impl TypeContext { pub fn new() -> TypeContext { TypeContext { symbol_table: HashMap::new(), + evar_table: HashMap::new(), existential_type_label_count: 0, } } @@ -342,6 +344,7 @@ impl TypeContext { fn unify(&mut self, t1: Type, t2: Type) -> TypeCheckResult { use self::Type::*; use self::TypeConst::*; + use self::TypeVar::*; match (&t1, &t2) { (&TConst(ref c1), &TConst(ref c2)) if c1 == c2 => Ok(TConst(c1.clone())), @@ -350,6 +353,22 @@ impl TypeContext { let t6 = self.unify(*t2.clone().clone(), *t4.clone().clone())?; Ok(TFunc(Box::new(t5), Box::new(t6))) }, + (&TVar(Univ(ref a)), &TVar(Univ(ref b))) => { + if a == b { + Ok(TVar(Univ(a.clone()))) + } else { + Err(format!("Couldn't unify universal types {} and {}", a, b)) + } + }, + (&TVar(Exist(ref a)), &TVar(Exist(ref b))) => { + //the interesting case!! + + if a == b { + Ok(TVar(Exist(a.clone()))) + } else { + Err(format!("Couldn't unify existential types {} and {}", a, b)) + } + }, _ => Err(format!("Types {:?} and {:?} don't unify", t1, t2)) } }