On Jan 10, 2008 11:54 PM, Luke Palmer <[EMAIL PROTECTED]> wrote:
> Can someone explain what the heck is going on here?

Evaluating (const EXPR) creates a closure object with a pointer to
'const' and a pointer to the EXPR thunk. Call this closure object C.
Evaluating (C undefined) calls 'const' with the EXPR and C thunks as
its arguments, which returns the EXPR thunk. The EXPR thunk is then
forced by your code. Evaluating (C undefined) again calls 'const' with
the EXPR and C pointers as its arguments again, which again returns
the *now forced* EXPR thunk.

I.e., evaluating (const EXPR) creates a closure with a pointer to a
single EXPR thunk, and then applying the same closure to some argument
multiple times uses that same EXPR thunk every time. An unoptimized
(\_ -> EXPR) creates a new thunk each time the function is applied to
an argument.

Hope that helps with understanding what is going on?

- Benja
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to