@zshipko@lindig
Hello,
I am trying to write an eval function to evaluate all forms of expressions.

let rec eval (env: environment) (e: expr) : value =
match e with
| Val v -> v
| Add (e1, e2) ->
(match eval env e1, eval env e2 with
| Int i1, Int i2 -> Int (i1 + i2)
| _,_ -> raise(Failure "Incompatible values on Add")
)
| Let (n, bexpr, body) ->
let bexpr_v = eval env bexpr in
eval ((n,bexpr_v)::env) body
| App (e1, e2) -> ?? (*Apply a function to an expression*)
| If (e1, e2, e3) -> ?? (*If ...then... else...*)
| LetRec (n, dexpr, body) -> ??
| Lambda (n, expr) -> ??

How can come up with an idea of writing eval for App and Lambda?
Thank you!

@lindig
Hello,
My value type currently has Int of int, Bool of bool and closure of stringexprexpr.
What else do i need to think more about eval lambda?
Thank you.

You didn’t show the type definition – I was speculating that it might be difficult to represent a lambda value. There are several choices. By any chance, is this a homework exercise?

An if expression yields a value that is computed by evaluating one of the branches. To decide which branch, the guarding expression must be evaluated first. If you have boolean values, the guarding expression should yield a boolean. I think this is easier than lambda expressions or function application.

Hi - this is a homework assignment from my course, but it is a common problem. The choice of names exactly matches the ones in our assignment. If you did find it on the internet, can you tell me where that was? Thanks.