polytype
A Hindley-Milner polymorphic typing system. Implements type inference via unification.
Usage
[]
= "1.1"
Provided by polytype
are the
Type
enum and
the Context
struct.
Unification:
let mut ctx = default;
let tbool = Constructed;
let tint = Constructed;
// t1: list(int → α) ; t2: list(β → bool)
let t1 = tlist;
let t2 = tlist;
ctx.unify.expect;
let t1 = t1.apply;
let t2 = t2.apply;
assert_eq!; // list(int → bool)
Apply a type context:
let mut ctx = default;
// assign t0 to int
ctx.unify.expect;
let t = Constructed;
assert_eq!;
let t = t.apply;
assert_eq!;
Independent instantiation:
let mut ctx = default;
let t1 = Constructed;
let t2 = Constructed;
let t1 = t1.instantiate_indep;
let t2 = t2.instantiate_indep;
assert_eq!;
assert_eq!;
Dependent instantiation:
use HashMap;
let mut ctx = default;
let t1 = Constructed;
let t2 = Constructed;
let mut bindings = new;
let t1 = t1.instantiate;
let t2 = t2.instantiate;
assert_eq!;
assert_eq!;
See the documentation for more details.