CC-delcont- Delimited continuations and dynamically scoped variables

Copyright(c) R. Kent Dybvig, Simon L. Peyton Jones and Amr Sabry
MaintainerDan Doel
PortabilityNon-portable (rank-2 types, generalized algebraic datatypes)
Safe HaskellNone




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) Source 
Monad m => MonadState Int (P ans m) Source 
MonadTrans (P ans) Source 
Monad m => Monad (P ans m) Source 
Functor m => Functor (P ans m) Source 
Monad m => Applicative (P ans m) Source 

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'.


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

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 b Source

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 where Source

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