Chung-chieh Shan wrote:
wren ng thornton wrote:
> 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).

Oh certainly. Depending on how the HOFs are used, however, that can lead to a very large grammar. The basic ADT approach works best when there are a small selection of actions to take or pass around (aka few states in the state machine).

For a more general solution you'll want to use something like HOAS or Template Haskell's AST, with explicit representations for general function application, let binding, and case expressions. That way the building blocks are small enough to keep the evaluator simple to maintain.

--
Live well,
~wren
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to