Closure

From HaskellWiki
Revision as of 18:06, 29 September 2010 by Griff (talk | contribs) (fixed typo)
Jump to navigation Jump to search

A closure, the opposite of a combinator, is a function that makes use of free variables in its definition. It 'closes' around some portion of its environment. for example

f x = (\y -> x + y)

f returns a closure, because the variable x, which is bound outside of the lambda abstraction is used inside its definition.

An interesting side note: the context in which x was bound shouldn't even exist anymore, and wouldn't, had the lambda abstraction not closed around x.