IT lexicon › Programming › Lambda lifting

Lambda lifting

Programming På svenska → Updated: 2026-11-05

Nested functions are moved out to the top level, and the variables they borrowed from their surroundings become extra parameters instead.

An inner function that reads a variable from its enclosing function has a problem once it turns into machine code: the variable isn't in its own stack frame. Lambda lifting solves this without building any object at all. The function is hoisted out, takes its free variables as arguments, and every call passes them along. Thomas Johnsson described the transformation in 1985 as a way of turning lazy functional programs into recursive equations.

The trick needs the compiler to see every call site. The moment the function escapes as a value, nobody knows who should supply the extra arguments, and closure conversion is the only option left. GHC therefore lifts selectively, late in the pipeline, only where it won't hurt register allocation — more parameters aren't free either.

← Back to the lexicon