[Haskell-cafe] Closures and pointfree functions

Derek Elkins derek.a.elkins at gmail.com
Mon Sep 3 15:21:45 EDT 2007

On Mon, 2007-09-03 at 20:44 +0200, Lars Oppermann wrote:
> Ah, thanks...
> However, I think I have just become more confused as to what makes a
> closure a closure. The defining principle seems to go along the lines
> some kind of context that is enclosed within the closure object. It
> was argued elsewhere [1] that a higher order function is not
> necessarily a closure. So, coming back to the Wiki example of
>   f x = (\y -> x + y)
> The free variable x in the lambda term refers to a variable bound
> outside of the actual term. However, I don't quite see how this can be
> seen as enclosing some kind of context... it's just a function
> returning a function, isn't it? This seems to be underlined by the
> fact that it can be rewritten in a pointfree fashion where there
> really is no binding whatsoever at the time of definition.
> If someone could point out a more specific example for showing where
> the difference between closures and higher-order functions could be
> drawn I'd be most grateful...

It's easy.  In somewhat loose terminology, closures and higher-order
functions are the same thing.  In somewhat more strict terminology, a
closure is a implementation technique for higher-order functions.

While it is usually easier to think of capturing the current lexical
frame, the categorical viewpoint may help here.  From the perspective of
category theory, all "closures" come from partial application.

More information about the Haskell-Cafe mailing list