Your expression contains Id
elements. To evaluate an expression to a value, you need to know the value for each Id
. This is provided by the environment: it should contain a value for each Id
element that you find. You need a function like lookup
val lookup: string -> environment -> value
val eval: environment -> expr -> value
such that you can call lookup "x" env
to get back Int(42)
when you implement eval
. In particular:
eval [("x", Int(42))] (Id "x") => Int(42)