From 2d36ad44d62ac22996f071a303036f36bab788d1 Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 9 Nov 2018 02:50:29 -0800 Subject: [PATCH] Converting over types WIP --- schala-lang/language/src/typechecking.rs | 26 +++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/schala-lang/language/src/typechecking.rs b/schala-lang/language/src/typechecking.rs index 4abbc00..635362d 100644 --- a/schala-lang/language/src/typechecking.rs +++ b/schala-lang/language/src/typechecking.rs @@ -6,7 +6,9 @@ use util::ScopeStack; pub type TypeName = Rc; pub struct TypeContext<'a> { - variable_map: ScopeStack<'a, Rc, Type<()>> + variable_map: ScopeStack<'a, Rc, Type<()>>, + evar_count: u32 + } type InferResult = Result; @@ -21,13 +23,20 @@ impl TypeError { } #[derive(Debug, Clone)] -enum Type { - Var(a), +enum Type { + Var(A), Const(TConst), - Arrow(Box>, Box>), - ExistentialVar(u32) + Arrow(Box>, Box>), } +enum TVar { + Universal(UniversalVar), + Existential(ExistentialVar) +} + +struct UniversalVar(Rc); +struct ExistentialVar(u32); + impl TypeIdentifier { fn to_monotype(&self) -> Type<()> { match self { @@ -73,6 +82,7 @@ impl<'a> TypeContext<'a> { pub fn new() -> TypeContext<'a> { TypeContext { variable_map: ScopeStack::new(None), + evar_count: 0 } } @@ -180,8 +190,10 @@ impl<'a> TypeContext<'a> { unimplemented!() } - fn allocate_existential(&mut self) -> Type<()> { - Type::ExistentialVar(0) + fn allocate_existential(&mut self) -> Type { + let n = self.evar_count; + self.evar_count += 1; + Type::Var(TVar::Existential(ExistentialVar(n))) } }