Struct polytype::Context
[−]
[src]
pub struct Context { /* fields omitted */ }
Context is a type environment, keeping track of substitutions and type variables. Useful for unifying (and inferring) types.
Methods
impl Context
[src]
fn substitutions(&self) -> &HashMap<u32, Type>
[src]
fn extend(&mut self, v: u32, t: Type)
[src]
Create a new substitution for the type variable numbered v
to the type t
.
fn new_variable(&mut self) -> Type
[src]
Create a new Type::Variable
from the next unused number.
fn unify(&mut self, t1: &Type, t2: &Type) -> Result<(), UnificationError>
[src]
Create constraints within the context that ensure the two types unify.
Examples
let mut ctx = Context::default(); let tbool = Type::Constructed("bool", vec![]); let tint = Type::Constructed("int", vec![]); fn tlist(tp: Type) -> Type { Type::Constructed("list", vec![Box::new(tp)]) } let t1 = tlist(Type::from(Arrow::new(tint, Type::Variable(0)))); let t2 = tlist(Type::from(Arrow::new(Type::Variable(1), tbool))); ctx.unify(&t1, &t2).expect("unifies"); let t1 = t1.apply(&ctx); let t2 = t2.apply(&ctx); assert_eq!(t1, t2);
Trait Implementations
impl Debug for Context
[src]
impl Clone for Context
[src]
fn clone(&self) -> Context
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more