Assuming your expression expression looks like
type expression = App of expression * expression
| Lambda of ident * expression
(* ... *)
you have a function subst (x:ident) (e1:expression) (e2:expression) : expressionthat replaces all free entries xwith e1in e2, and you want a normal order evaluation, your code should look something like this:
let rec eval exp =
match exp with
(* ... *)
| App (f, arg) -> match eval f with Lambda (x,e) -> eval (subst x arg e)
The function substshould work as follows:
.
lambdas , , ( , ).
, , .