Akh Javascript monad transformer library
Delimted continuation monad and monad transformer forThe delimited continuation transformer, DContT
, layers delimited control over a monad. The base type, DCont
, provides delimited control on its own.
The delimited continuation transformer is a monad, functor, and applicative functor.
# To use as standalone package $ npm install --save akh.dcont # To use as part of akh library $ npm install --save akh
Usage
The dcont monad/transformer implements the [Fantasy Land][fl] monad, function, and applicative functor interfaces.
// Delimited continuation monadDContDCont // Delimited continuation monad transformerDContTDContT
DCont.run(m, k)
, m.run(k)
Perform a delimited continuation computation m
and complete with outer continuation k
.
const liftM2 = baseliftM2const dcont = dcont var list = liftM2 const c = dcont
DContT.run(m, k)
Same as DContT::run
but for transformed types
Delimited Control Interface
All DCont operations and methods are defined on both the type and its instances.
M.newPrompt
Create a new unique prompt that can be used to delimit a continuation.
M.pushPrompt(prompt, c)
Push prompt
on to the control stack, delimiting the continuation, and evaluate computation c
.
M.withSubCont(prompt, f)
Capture the continuation delimited by prompt
and call f
with it. f
maps the delimited continuation to a computation. The delimited control structure passed to f
should be considered opaque.
M.pushSubCont(subk, c)
Push an entire sub continuation sunk
onto the stack and evaluate computation c
.
M.reset(f)
Delimit a continuation, calling f
with delimiting prompt. f
maps the prompt to a computation that is performed inside the delimited context.
M.shift(p, f)
Capture the continuation delimited by p
, reify the continuation, and pass it to f
. f
can invoke the reified continuation with a computation to evaluate the rest of the delimited continuation, or return a computation directly to break out.
Contributing
Contributions are welcome.
To get started:
$ cd akh-dcont$ npm install # install dev packages $ npm test # run tests