Converting over types

WIP
This commit is contained in:
greg 2018-11-09 02:50:29 -08:00
parent 21132a369c
commit 2d36ad44d6
1 changed files with 19 additions and 7 deletions

View File

@ -6,7 +6,9 @@ use util::ScopeStack;
pub type TypeName = Rc<String>; pub type TypeName = Rc<String>;
pub struct TypeContext<'a> { pub struct TypeContext<'a> {
variable_map: ScopeStack<'a, Rc<String>, Type<()>> variable_map: ScopeStack<'a, Rc<String>, Type<()>>,
evar_count: u32
} }
type InferResult<T> = Result<T, TypeError>; type InferResult<T> = Result<T, TypeError>;
@ -21,13 +23,20 @@ impl TypeError {
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
enum Type<a> { enum Type<A> {
Var(a), Var(A),
Const(TConst), Const(TConst),
Arrow(Box<Type<a>>, Box<Type<a>>), Arrow(Box<Type<A>>, Box<Type<A>>),
ExistentialVar(u32)
} }
enum TVar {
Universal(UniversalVar),
Existential(ExistentialVar)
}
struct UniversalVar(Rc<String>);
struct ExistentialVar(u32);
impl TypeIdentifier { impl TypeIdentifier {
fn to_monotype(&self) -> Type<()> { fn to_monotype(&self) -> Type<()> {
match self { match self {
@ -73,6 +82,7 @@ impl<'a> TypeContext<'a> {
pub fn new() -> TypeContext<'a> { pub fn new() -> TypeContext<'a> {
TypeContext { TypeContext {
variable_map: ScopeStack::new(None), variable_map: ScopeStack::new(None),
evar_count: 0
} }
} }
@ -180,8 +190,10 @@ impl<'a> TypeContext<'a> {
unimplemented!() unimplemented!()
} }
fn allocate_existential(&mut self) -> Type<()> { fn allocate_existential(&mut self) -> Type<TVar> {
Type::ExistentialVar(0) let n = self.evar_count;
self.evar_count += 1;
Type::Var(TVar::Existential(ExistentialVar(n)))
} }
} }