A student asked me why the following happens. In explaining I thought
that it may be easy to avoid the observed behavior.
In hugs98, when you input
> paired f (x,y) = (f x, f y)
> pair x = (x,x)
> test1 = paired f $ pair 42
> where f x = length [1..10000]
> test2 = paired (\x -> y) $ pair 42
> where y = length [1..10000]
Running test1 evaluates `length [1..10000]` twice, running test2
evaluates it only once.
The reason is of course that in test2 there is a heap node that can be
updated with an indirection to the result of `length [1..10000]` and
which is shared among the two applications whereas in test1, the root
of the applications are updated, but they are not shared.
In
> test3 = paired f $ pair 42
> f x = fNewName
> fNewName = length [1..10000]
we have that sharing again.
What I would like to know is: wouldn't it make sense to have the
transformation
f x = e where e does not mention x
-->
f x = f'
f' = e
in hugs? Did I miss anything?
Comments?
Marko
--
Marko Schütz [EMAIL PROTECTED]
http://www.ki.informatik.uni-frankfurt.de/~marko/