Question

2. Given below is SML code that implements a simple way to define expressions and operations on them: datatype exp = Constant of int Negate of exp | Add of exp

* exp fun eval e = case e of Constant (i) => i Negate el => ~ (eval el) | Add (el, e2) => (eval el) + (eval e2) eval (Add (Constant 19, Negate (Constant 4))); (* result is 15 *)

Fig: 1