TriceratopsTriceratypes

Practice ML-style type inference step by step
Work in progress - bugs or suggestions? sfreund@williams.edu

Expression Syntax

fn x => e lambda f x application let x = e1 in e2 let binding if c then t else e conditional (e1, e2) tuple + - * < > operators nil empty list x :: xs cons

Declarations

fun f x = e; function def fun f 0 = e1 | f n = e2; pattern match

Constraint Syntax

t1 = int integer type t1 = bool boolean type t1 = t2 -> t3 function type t1 = t2 * t3 tuple type t1 = t2 list list type

Unification Rules

Decompose:
A→B = C→D  ⟹  A=C, B=D
A*B = C*D  ⟹  A=C, B=D
A list = B list  ⟹  A=B
Eliminate:
x=A, C=D  ⟹  [A/x]C = [A/x]D

Enter an expression below or start with an example:

more examples

Parse Trees with Type Variables

Phase 1: Generate Constraints

0 / 0

Phase 2: Unification

Type Inference Complete!