[clean-list] local functions as CAF

Paul de Mast demast.pjf@hsbrabant.nl
Wed, 21 Mar 2001 17:20:11 +0100


Hi,


I experienced (in a more complex situation then below) that when you are
structering a program so that definitions are locally defined as much as
possible this can cause serious performance penalty:

A local expression is treated as a constant, but only to the directly
surrounding function.

In the following definition y is 'evaluated' 10 times (because f is
evaluated 10 times):

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?

Paul de Mast