[Haskell-cafe] Re: Can this be done?
ccshan at post.harvard.edu
Thu Feb 12 19:55:20 EST 2009
wren ng thornton <wren at freegeek.org> wrote in article <4993BBEE.9070603 at freegeek.org> in gmane.comp.lang.haskell.cafe:
> It's ugly, but one option is to just reify your continuations as an ADT,
> where there are constructors for each function and fields for each
> variable that needs closing over. Serializing that ADT should be simple
> (unless some of those functions are higher-order in which case you run
> into the same problem of how to serialize the function arguments). In
> GHC's STG machine this representation shouldn't have much overhead,
> though it does require the developer to do the compiler's job.
FWIW, this idea is called defunctionalization (due to Reynolds),
and it works for higher-order functions as well (because you can
defunctionalize those function arguments in the same way).
People in many fields put a lot of effort into turning their programs
into state machines...
Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig
"Attending a mathematics lecture is like walking through a
thunderstorm at night. Most of the time you are lost, wet
and miserable but at rare intervals there is a flash of
lightening and the whole countryside is lit up." - Tom Koerner
More information about the Haskell-Cafe