Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I know I am repeating a previous comment but the author correctly explains it here

http://notes-on-haskell.blogspot.com/2007/02/whats-wrong-wit...

In Haskell all parameters are lazy by default, which effectively turns every parameter into a closure.

for e.g., consider the code

boost x = map (x) [1..10]

total = sum (boost 2)

On invocation of the sum function, the (boost 2) is not necessarily evaluated. Instead a reference to ((x -> map (x) [1..10]) 2) is passed in to sum. So sum will now end up actually accessing x which has been bound to the value 2. When written this way, the binding of x to 2 is more explicit, but this is the way Haskell evaluates expressions and function calls by default. So (boost 2) might not actually look like a closure, but it effectively is.

Thanks to Haskell's purity, GHC can actually turn this expression into a plain for loop with no lists being constructed. At least in the context of Haskell, this makes discussions of the "runtime structure that represents a closure" meaningless as there may be no run time structures at all, not even a list, much less a closure.

Any value, which doesn't even look like a function/closure could be referencing an unevaluated function with any kind of "variable"[1] bindings.

[1] - Haskell is pure and does not have variables, only constants and functions.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: