Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including akh.dcont with all npm packages installed. Try it out:

var akhDcont = require("akh.dcont")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

akh.dcont v0.0.1

Akh delimited continuation monad transformer and monad

Delimted continuation monad and monad transformer for Akh Javascript monad transformer library

The 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


The dcont monad/transformer implements the [Fantasy Land][fl] monad, function, and applicative functor interfaces.

Fantasy Land logo

// Delimited continuation monad

// Delimited continuation monad transformer
require('akh').DContT, k),

Perform a delimited continuation computation m and complete with outer continuation k.

const liftM2 = require('akh').base.liftM2
const dcont = require('akh').dcont

var list = liftM2.bind(null, (x, y) -> [x, y])

const c = dcont.reset((p) =>
    liftM2((x, y) => x + y,
        dcont.shift(p, k =>
            list(k(of(1)), k(of(2))),
        dcont.shift(p, k =>
            list(k(of(10)), k(of(20)))), console.log) // logs: [[11, 21], [12, 22]], 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.


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.


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.


Contributions are welcome.

To get started:

$ cd akh-dcont
$ npm install # install dev packages
$ npm test # run tests


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free