lambda lifting


lambda lifting

A program transformation to remove free variables. Anexpression containing a free variable is replaced by afunction applied to that variable. E.g.

f x = g 3 where g y = y + x

x is a free variable of g so it is added as an extra argument:

f x = g 3 x where g y x = y + x

Functions like this with no free variables are known assupercombinators and are traditionally given upper-case namesbeginning with "$". This transformation tends to produce manysupercombinators of the form f x = g x which can be eliminatedby eta reduction and substitution. Changing the order ofthe parameters may also allow more optimisations. Referencesto global (top-level) constants and functions are nottransformed to function parameters though they are technicallyfree variables.

A closely related technique is closure conversion. See alsoFull laziness.