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

Portability Non-portable (generalized algebraic datatypes) Experimental Dan Doel

Contents

Description

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 (http://www.cs.indiana.edu/~sabry/papers/monadicDC.pdf)

This module implements the generalized sequence type used as a stack of frames representation of the delimited continuations.

Synopsis

# Sequence datatype

data Seq seg ans a whereSource

This is a generalized sequence datatype, parameterized by three types: seg : A constructor for segments of the sequence.

ans : the type resulting from applying all the segments of the sequence. Also used as a region parameter.

a : The type expected as input to the sequence of segments.

Constructors

 EmptyS :: Seq seg ans ans PushP :: Prompt ans a -> Seq seg ans a -> Seq seg ans a PushSeg :: seg ans a b -> Seq seg ans b -> Seq seg ans a

# Sub-sequences

type SubSeq seg ans a b = Seq seg ans b -> Seq seg ans aSource

A type representing a sub-sequence, which may be appended to a sequence of appropriate type. It represents a sequence that takes values of type a to values of type b, and may be pushed onto a sequence that takes values of type b to values of type ans.

appendSubSeq :: SubSeq seg ans a b -> SubSeq seg ans b c -> SubSeq seg ans a cSource

Concatenate two subsequences

pushSeq :: SubSeq seg ans a b -> Seq seg ans b -> Seq seg ans aSource

Push a sub-sequence onto the front of a sequence

splitSeq :: Prompt ans b -> Seq seg ans a -> (SubSeq seg ans a b, Seq seg ans b)Source

Splits a sequence at the given prompt into a sub-sequence, and the rest of the sequence