CC-delcont-0.2: Delimited continuations and dynamically scoped variables

PortabilityNon-portable (rank-2 types, generalized algebraic datatypes)
MaintainerDan Doel




A monadic treatment of delimited continuations.

Adapted from the paper A Monadic Framework for Delimited Continuations, by R. Kent Dybvig, Simon Peyton Jones and Amr Sabry (

This module implements the generation of unique prompt names to be used as delimiters.


P, The prompt generation monad

data P ans m a Source

The prompt generation monad. Represents the type of computations that make use of a supply of unique prompts.


MonadReader r m => MonadReader r (P ans m) 
Monad m => MonadState Int (P ans m) 
MonadTrans (P ans) 
Monad m => Monad (P ans m) 
Functor m => Functor (P ans m) 

The Prompt type

data Prompt ans a Source

The prompt type, parameterized by two types: * ans : The region identifier, used to ensure that prompts are only used within the same context in which they are created.

  • a : The type of values that may be returned through a given prompt. For instance, only prompts of type 'Prompt r a' may be pushed onto a computation of type 'CC r a'.


MonadDelimitedCont (Prompt ans) (SubCont ans Identity) (CC ans) 
Monad m => MonadDelimitedCont (Prompt ans) (SubCont ans m) (CCT ans m) 

runP :: Monad m => P ans m ans -> m ansSource

Runs a computation that makes use of prompts, yielding a result in the underlying monad.

newPromptName :: Monad m => P ans m (Prompt ans a)Source

Generates a new, unique prompt

eqPrompt :: Prompt ans a -> Prompt ans b -> Equal a bSource

Tests to determine if two prompts are equal. If so, it provides evidence of that fact, in the form of an Equal.

A type equality datatype

data Equal a b whereSource

A datatype representing type equality. The EQU constructor can be used to provide evidence that two types are equivalent.


EQU :: Equal a a 
NEQ :: Equal a b