From my moving-target understanding of closures, I'm guessing this has a closure
let succ = add 1
add x = xadder
where xadder y = x + y
in succ 3
Now, can someone explain in words how the closure system is at work here? I see that the add 1 is being "baked in". Do we say this is a closure on add 1? (Closure wording is confusing.) The enclosing scope of add contains 1; however, xadder is what succ ultimately becomes, which has 1 in its scope in that when xadder is defined, the x argument will be the 1 of add 1. Or am I missing something?
Researching closures vis-a-vis Haskell, I've seen the argument that,
- no, Haskell doesn't have closures,
- yes, Haskell is lazy, everything can be seen as a closure, as even a value can be seen as a function without argument waiting to be evaluated (and so capturing its environment until it gets evaluated).
This was taken from an older Haskell textbook (Introduction to Functional Programming Systems Using Haskell by Davie).
LB