[Haskell-cafe] Can this be done?
wren ng thornton
wren at freegeek.org
Thu Feb 12 01:04:30 EST 2009
Cristiano Paris wrote:
> Manlio Perillo wrote:
> > Cristiano Paris ha scritto:
> > > I'm interested in the possibility of
> > > stopping/pickling/unpickling/resuming a computation.
> > Not sure this is a good thing in a web application.
> I'm thinking of complex workflows and inversion of control.
> A computation may stop, return a response, wait for a new request to
> be passed by the HTTP server and return back a new response, stopping
> again. This goes on forever. All this can be achieved in Haskell but
> the serialization path, which is crucial for swapping out idle
> sessions (containing the stopped computation) or to get back to life
> after server stopped (for maintenance for instance). I guess this
> should be doable in Clean, which has mechanisms to do dynamic binding
> and serialization of closures.
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.
More information about the Haskell-Cafe