Module Cf_cmonad

module Cf_cmonad: sig .. end
The continuation monad and its operators.


Overview


The continuation monad is provided here mostly for reference purposes, since it is helpful to refer to it when lifting into a more complex monad.

A continuation monad represents a computation composed of stages that can be interrupted, resumed and rescheduled. Because Objective Caml is an eager language programming in the continuation-passing style (CPS) can be simplified by the use of the continuation monad and its operators.

Note: see the Cf_gadget module for an example of its use.

Types

type ('x, 'a) t = ('a -> 'x) -> 'x 
The continuation monad: a function for passing intermediate results from continuation context to continuation context.

Modules

module Op: sig .. end
A module containing the ( >>= ) binding operator for composition of continuation monads.

Operators

val nil : ('x, unit) t
A monad that returns unit and performs no operation.
val return : 'a -> ('x, 'a) t
Use return a to produce a monad that returns a as an intermediate result from the current continuation.
val init : 'x -> ('x, 'a) t
Use init x to produce a monad that discards the current intermediate result and returns x as the continuation context.
val cont : ('x -> 'x) -> ('x, unit) t
Use cont f to produce a monad that passes the calling continuation to the function f and returns the unit value as an intermediate result.
val eval : ('x, unit) t -> 'x -> 'x
Use eval m to evaluate the continuation monad to produce a function from initial continuation context to final continuation context.