[clean-list] local functions as CAF
Martin Wierich
martinw@cs.kun.nl
Mon, 26 Mar 2001 10:20:18 +0200
Hi Paul,
Paul de Mast wrote:
> Start = filter f [1..10]
> where
> f x = x > y
> where
> y = 2*3 // or a complex calculation
>
> If we put y on the same level as f y is evaluated only once:
>
> Start = filter f [1..10]
> where
> f x = x > y
>
> y = 2*3 // or a complex calculation
>
> Is it possible that the compiler optimises the first situation by lifting y
> to the same level as f?
In principle yes, of course. It would somehow be different from pure graph
rewriting semantics but I wouldn't care about that as long as the outcome of the
program stays the same. One had to take care with uniqueness: imagine y would
deliver a unique array...
cheers
Martin Wierich