[Notes by Jeff Vaughan] AST/Interpreters Using SML datatypes we can implement a very basic interpreter to operate on sets. type set = int list datatype opr = Union | Intersection datatype exp = Set_exp of set | Opr_exp of exp * opr *exp fun eval(e: exp): set = case e of Set_exp(s) => s | Opr_exp(e1, Union, e2) => (eval(e1))@(eval(e2)) | Opr_exp(e1, Intersection, e2) => List.filter ( fn(x:int) => List.exists (fn(y)=>y=x) (eval e2)) (eval e1) I think it's all straightforward. Please notice that multiple copies of a single element can wind up in a set after a union. This is a bug - it's not true to the definition of a set, and waste's space. One way to fix it is to call ListMergeSort.uniqueSort after appending the lists. I'm going to cop out and post a link to the notes from the 2002sp lecture on ASTs and substitution http://www.cs.cornell.edu/courses/cs312/2002sp/lectures/lec14.asp There are few basics examples of non-recursive substitution, and an overview of an Abstract syntax for a more interesting language than my set language.