DEV Community

Discussion on: Function vs Object

Collapse
citizen428 profile image
Michael Kohl

Closures aren't pure FP.

Lambda calculus has functions with free variables. Here's the Haskell definition of a closure:

wiki.haskell.org/Closure

Collapse
stereobooster profile image
stereobooster Author

I tried to find the source for this definition (which I remembered myself, but wasn't sure where I got it from, probably from exactly this wiki). Interestingly nothing else refers open lambda term as closure. In every source that I met closures are treated as implementation detail of lambda terms🤔.

(I agree that closures are "functional", this is lambda term + environment)

Thread Thread
citizen428 profile image
Michael Kohl

Not sure what you mean, even the Wikipedia entry on closures relates them to free variables in LC:

en.m.wikipedia.org/wiki/Closure_(c...

Thread Thread
stereobooster profile image
stereobooster Author • Edited on

Yes it uses free variables. My question is closure ≡ open lambda term (open lambda term - the one with free variables)? Because from implementation point of view closed lambda terms can be closures as well.

(This is just some thoughts out loud. Not questioning your comment)

Collapse
codemouse92 profile image
Jason C. McDonald • Edited on

Basically, from what I've understood, a closure is still functional, but according to some purists, it's not "pure functional" because it has state.

Not that I really prioritize "purity" in terms of functional programming. Avoiding state is good for the most part, but at some point it becomes relatively impractical. Common sense required.