When do one know when to save the value in call-by-need?
The only bad way I have come up with is to check if there is any
lambda function nested and the best way to do that is to check the
application stack in the enviroment but I would like a better way as
to avoid modifing the code to return an env everywhere
ex.
add x = (x 5)+(x 7)
main = add (\x -> x) -- should return 12
Since I currently save after every lookup I will save the result of (x
5) in x which is wrong and how can I best detect this? Is the
application stack the best way?
[5,7] == [7]
but should it also support more difficult cases like
add x = (x 5) + (x 7)
main = add (1 + \x-> x)
or should this be stopped by parser
This should result in type error.
You don't have to save 5 in x because x is a function. An example when
this is needed is this:
(\x -> x+x) (1+2)
In this case x is first bound to (1+2). After the first computation x
is updated to 3 and then when x is accessed for a second time then it
already has the computed value 3.
Krasimir
Since the language is untyped, it is sufficient to raise an error in
the interpreter when you visit the + node and see that the operands
are not two numbers.
cheers,
Arnar
like the first example:
add x = (x 5) + (x 7)
should this be allowed?
Sorry if I talk noncense as I am a bit tired but don't really have
time to think... :)
On Tue, Mar 16, 2010 at 22:55, llarsson <llar...@student.chalmers.se> wrote:
> like the first example:
> add x = (x 5) + (x 7)
>
> should this be allowed?
Yes, this should be allowed.
cheers,
Arnar