let floating

let floating

(programming)A program transformation used in functional programming to implement full laziness. E.g. the function

f x = x + sqrt 4

can be expressed as

f x = let t = sqrt 4 in x + t

but note that t does not depend on the argument x so we canautomatically transform this to

t = sqrt 4f x = x + t

Making t into a global constant which need only be evaluatedat most once, rather than every time f is called. The generalidea is to float each subexpression as far out (toward thetop level) as possible to maximise sharing.