Converting over types
WIP
This commit is contained in:
parent
21132a369c
commit
2d36ad44d6
@ -6,7 +6,9 @@ use util::ScopeStack;
|
||||
pub type TypeName = Rc<String>;
|
||||
|
||||
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>;
|
||||
@ -21,13 +23,20 @@ impl TypeError {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
enum Type<a> {
|
||||
Var(a),
|
||||
enum Type<A> {
|
||||
Var(A),
|
||||
Const(TConst),
|
||||
Arrow(Box<Type<a>>, Box<Type<a>>),
|
||||
ExistentialVar(u32)
|
||||
Arrow(Box<Type<A>>, Box<Type<A>>),
|
||||
}
|
||||
|
||||
enum TVar {
|
||||
Universal(UniversalVar),
|
||||
Existential(ExistentialVar)
|
||||
}
|
||||
|
||||
struct UniversalVar(Rc<String>);
|
||||
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<TVar> {
|
||||
let n = self.evar_count;
|
||||
self.evar_count += 1;
|
||||
Type::Var(TVar::Existential(ExistentialVar(n)))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user