Your assignment is to implement in ML (SML or Caml) term substitutions, term matching and unification, as presented in the slides.
Substitutions, matching and unification operate on the following datatype:
datatype term =
Var of string
| Symbol of string * (term list);
In Caml, the same datatype definition would be:
type term =For example, the term
Var of string
| Symbol of string * (term list);;
Succ(Zero)would be represented as
Symbol("Succ", [Symbol("Zero",[])])and
Pair(x, Nothing)would be represented as
Symbol("Pair", [Var "x", Symbol("Nothing",[])]) in SMLand
Symbol("Pair", [Var "x"; Symbol("Nothing",[])]) in Caml.You must implement the two functions matches and unify given during the lecture, and their type must be:
matches : term -> term -> substitutiongiven an appropriate representation for substitutions.
unify : term -> term -> substitution
compose : substitution -> substitution -> substitutionimplementing the composition of substitutions, and
apply : substitution -> term -> termwhich applies a substitution to a term.
If you have any question, please post it in the class mailing list.
For your information, my own implementation is 100 lines long (and includes
multi-lines comments). Yours shouldn't be much longer...