Fresh type var

This commit is contained in:
greg 2019-02-23 01:27:32 -08:00
parent 2cc3367666
commit 8dc34e4b49

View File

@ -30,7 +30,7 @@ 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>,
unification_table: InPlaceUnificationTable<TypeVar>, unification_table: InPlaceUnificationTable<TypeVar>,
//evar_count: u32 type_var_count: usize,
} }
/// `InferResult` is the monad in which type inference takes place. /// `InferResult` is the monad in which type inference takes place.
@ -207,7 +207,7 @@ impl<'a> TypeContext<'a> {
TypeContext { TypeContext {
variable_map: ScopeStack::new(None), variable_map: ScopeStack::new(None),
unification_table: UnificationTable::new(), unification_table: UnificationTable::new(),
//evar_count: 0 type_var_count: 0,
} }
} }
@ -372,6 +372,12 @@ impl<'a> TypeContext<'a> {
(a, b) => TypeError::new(format!("{:?} and {:?} do not unify", a, b)), (a, b) => TypeError::new(format!("{:?} and {:?} do not unify", a, b)),
} }
} }
fn fresh_type_variable(&mut self) -> TypeVar {
let n = self.type_var_count;
self.type_var_count += 1;
TypeVar(n)
}
} }
#[cfg(test)] #[cfg(test)]