polytype
A Hindley-Milner polymorphic typing system. Implements type inference via unification.
Usage
[]
= "1.2"
Provided by polytype
are the
Type
enum and
Context
struct, and the macros
tp!
and
arrow!
which
help to concisely create
types.
Unification:
let mut ctx = default;
// t1: list(int → α) ; t2: list(β → bool)
let t1 = tp!;
let t2 = tp!;
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 = tp!;
assert_eq!;
let t = t.apply;
assert_eq!;
Independent instantiation:
let mut ctx = default;
let t1 = tp!;
let t2 = tp!;
let t1 = t1.instantiate_indep;
let t2 = t2.instantiate_indep;
assert_eq!;
assert_eq!;
Dependent instantiation:
use HashMap;
let mut ctx = default;
let t1 = tp!;
let t2 = tp!;
let mut bindings = new;
let t1 = t1.instantiate;
let t2 = t2.instantiate;
assert_eq!;
assert_eq!;
See the documentation for more details.