unif-rules
unif-rules
The unification algorithm takes a set of pairs of types that are supposed to be equal. A system of constraints looks like
the following set
{(s1 , t1 ), (s2 , t2 ), ..., (sn , tn )}
Each pair is called an equation. A (lifted) substitution solves an equation (s, t) if (s) = (t). It solves a constraint
set if (si ) = (ti ) for every (si , ti ) in the constraint set. The unification algorithm will return a substitution that
solves the given constraint set (if a solution exists).
You will remember from lecture that the unification algorithm consists of four transformations. These transforma-
tions can be expressed in terms of how an action on the first element of the unification problem affects the remaining
elements.
Given a constraint set C
(a) Delete rule: If s and t are are equal, discard the pair, and unify C 0 .
(b) Orient rule: If t is a variable, and s is not, then discard (s, t), and unify {(t, s)} [ C 0 .
(c) Decompose rule: If s = TyConst(name,
Sn [s1 ; . . . ; sn ]) and t = TyConst(name, [t1 ; . . . ; tn ]), then
discard (s, t), and unify C 0 [ i=1 {(si , ti )}.
(d) Eliminate rule: If s is a variable, and s does not occur in t, substitute s with t in C 0 to get C 00 . Let be
the substitution resulting from unifying C 00 . Return updated with s 7! (t).
(e) If none of the above cases apply, it is a unification error (your unify function should return the None
option in this case).
In our system, function, integer, list, etc. types are the terms; TyVars are the variables.