[Haskell-cafe] Re: Can this be done?

Derek Elkins derek.a.elkins at gmail.com
Thu Feb 12 21:11:27 EST 2009

On Thu, 2009-02-12 at 19:55 -0500, Chung-chieh Shan wrote:
> 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...
This paper by Ezra Cooper and Phil Wadler is an interesting recent
development in the theory of defunctionalization and very relevant to
this particular topic as well:

More information about the Haskell-Cafe mailing list