# [Haskell-cafe] Closures and pointfree functions

Lars Oppermann loppermann at acm.org
Mon Sep 3 14:44:20 EDT 2007

```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...

On 9/3/07, Derek Elkins <derek.a.elkins at gmail.com> wrote:
> On Mon, 2007-09-03 at 19:47 +0200, Lars Oppermann wrote:
> > Dear all,
> >
> > there is an example for a function returning a closure given as
> >   f x = (\y -> x + y)
> >
> > Another way to achieve the same effect would be to write
> >   f' x = (+) x
> >
> > which to me as a beginner looks somewhat like pointfree style.
> >
> > Would f' be considered to return a closure
>
> Going backwards:
>
> Yes.
>
> The pointfree "solution" in this case would simply be f' = (+)
>
> Note that f x = \y -> x + y is written that way for emphasis and is
> identical to f x y = x + y
>
>
```