[jhc] Substitutions.

John Meacham john at repetae.net
Sat Feb 23 18:13:21 EST 2008

On Sat, Feb 23, 2008 at 03:52:29PM +0100, Lemmih wrote:
> I've encountered something I don't understand in E.Subst.
> The substitution routine is very eager to inline stuff. It inlines all
> the simple applications it can find.
> Consider the following example:
> (\a -> a+a) expensive
> The substitution routine will inline that to:
> expensive+expensive
> Wouldn't it be prudent to generate this instead:
> let a = expensive in a + a

An invariant is that the only things that may ever appear as arguments to
functions or data constructors are atoms. This ensures that beta
reduction is always beneficial and that 'let' statements are the one and
only way to allocate thunks. GHC core has the same restriction for the
same reason, it makes a whole lot of transformations a lot simpler.


John Meacham - ⑆repetae.net⑆john⑈

More information about the jhc mailing list