data Exp = ... | Let String Exp Exp | Ref String ex2 :: Exp ex2 = Let "x" ( Const 3 ) ( Times ( Ref "x" ) (Ref "x" ) ) type Env = ( String -> Integer ) value :: Env -> Exp -> Integer value env x = case x of Ref n -> env n Let n x b -> value ( \ m -> if n == m then value env x else env m ) b Const i -> i Plus x y -> value env x + value env y Times x y -> value env x * value env y