liboleg-2010.1.9.0: An evolving collection of Oleg Kiselyov's Haskell modules




data CC p m a Source

Delimited-continuation monad transformer It is parameterized by the prompt flavor p The first argument is the regular (success) continuation, the second argument is the bubble, or a resumable exception


MonadTrans (CC p) 
Monad m => Monad (CC p m)

CC monad: general monadic operations

MonadIO m => MonadIO (CC p m) 

type SubCont p m a b = CC p m a -> CC p m bSource

The captured sub-continuation

type CCT p m a w = SubCont p m a w -> CC p m wSource

The type of control operator's body

type Prompt p m w = (forall x. CCT p m x w -> p m x, forall x. p m x -> Maybe (CCT p m x w))Source

Generalized prompts for the answer-type w: an injection-projection pair

pushPrompt :: Monad m => Prompt p m w -> CC p m w -> CC p m wSource

Basic Operations of the delimited control interface

takeSubCont :: Monad m => Prompt p m w -> CCT p m x w -> CC p m xSource

Create the initial bubble

pushSubCont :: Monad m => SubCont p m a b -> CC p m a -> CC p m bSource

Apply the captured continuation

runCC :: Monad m => CC (p :: (* -> *) -> * -> *) m a -> m aSource

abortP :: Monad m => Prompt p m w -> CC p m w -> CC p m anySource

Useful derived operations

shiftP :: Monad m => Prompt p m w -> ((a -> CC p m w) -> CC p m w) -> CC p m aSource

shift0P :: Monad m => Prompt p m w -> ((a -> CC p m w) -> CC p m w) -> CC p m aSource

controlP :: Monad m => Prompt p m w -> ((a -> CC p m w) -> CC p m w) -> CC p m aSource

data PS w m x Source

The extreme case: prompts for the single answer-type w. The monad (CC PS) then is the monad for regular (single-prompt) delimited continuations

ps :: Prompt (PS w) m wSource

There is only one generalized prompt of the flavor PS for a given answer-type w. It is defined below

data P2 w1 w2 m x Source

Prompts for the closed set of answer-types The following prompt flavor P2, for two answer-types w1 and w2, is given as an example. Typically, a programmer would define their own variant data type with variants for the answer-types that occur in their program.

p2L :: Prompt (P2 w1 w2) m w1Source

p2R :: Prompt (P2 w1 w2) m w2Source

data PP m x Source

Prompts for the open set of answer-types

data PM c m x Source

The same as PP but with the phantom parameter c The parameter is useful to statically enforce various constrains (statically pass some information between shift and reset) The prompt PP is too dynamic: all errors are detected dynamically See Generator2.hs for an example

pm :: Typeable w => Prompt (PM c) m wSource

data PD m x Source

Open set of answer types, with an additional distinction (given by integer identifiers) This prompt flavor corresponds to the prompts in the Dybvig, Peyton-Jones, Sabry framework (modulo the Typeable constraint).

as_prompt_type :: Prompt p m w -> w -> Prompt p m wSource

It is often helpful, for clarity of error messages, to specify the answer-type associated with the prompt explicitly (rather than relying on the type inference to figure that out). The following function is useful for that purpose.