my first idea was (not considering the application stack)
type Var = (Env, Exp)
type Env = [(Ident, Var)]
However this is not valid haskell so one needs to make a data type
instead that can be viewed as above but in either case one has a
chicken & the egg problem. If one wants to add an element/variable to
the enviroment one wants the Env pointer of Var to point to the
resulting Env. Only way I can come up with is very ugly so I think
there is a fundamental error.
In Haskell you could use something like
type Closure = (Exp, Env)
type Env = Ident -> Value -- or [(Ident, Value)] if you want to use lookup
The "tricky" part is that Values need (for call-by-need) to be either
concrete values *or* closures.
data Value = V ConcreteValue | C Closure
data ConcreteValue = IntV Integer | BoolV Bool | ...
This is one possible way of structuring things.
hth,
Arnar
a = \x -> \y -> x+y
Example of adding a to the enviroment
Env = [(a, A]
Closure for:
A = ((\x -> \y -> x+y), [])
|
----------------------------|
|
Env for it to be evaluated should of course contain itself otherwise
recusion would be impossible but this creates a chicken & egg problem