Difference between revisions of "Closure"
Jump to navigation
Jump to search
BrettGiles (talk | contribs) (HaWiki migration) |
m |
||
(One intermediate revision by one other user not shown) | |||
Line 3: | Line 3: | ||
f x = (\y -> x + y) |
f x = (\y -> x + y) |
||
</haskell> |
</haskell> |
||
+ | |||
<hask>f</hask> returns a closure, because the variable <hask>x</hask>, which is bound outside of the [[lambda abstraction]] is used inside its definition. |
<hask>f</hask> returns a closure, because the variable <hask>x</hask>, which is bound outside of the [[lambda abstraction]] is used inside its definition. |
||
+ | |||
− | An interesting |
+ | An interesting side note: the context in which <hask>x</hask> was bound shouldn't even exist anymore, and wouldn't, had the lambda abstraction not closed around x. |
[[Category:Glossary]] |
[[Category:Glossary]] |
Latest revision as of 13:53, 1 January 2017
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.