Module Cf_scmonad

module Cf_scmonad: sig .. end
The state-continuation monad and its operators.


Overview

The state-continuation monad is provided here purely for reference purposes. It may be helpful as an example of how to lift the continuation monad into more complex monads.

Types

type ('s, 'x, 'a) t = ('s -> 'x, 'a) Cf_cmonad.t 
The state-continuation monad.

Modules

module Op: sig .. end
The continuation monad: a function for passing intermediate results from continuation context to continuation context with an encapsulated state value at each stage.

Operators

val nil : ('s, 'x, unit) t
A monad that returns unit and performs no operation.
val return : 'a -> ('s, 'x, 'a) t
Use return a to produce a monad that returns a as an intermediate result from the current continuation.
val init : 'x -> ('s, '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) -> ('s, '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 load : ('s, 'x, 's) t
A monad that returns the encapsulate state as an intermediate result.
val store : 's -> ('s, 'x, unit) t
Use store s to produce a monad with s as the value of its encapsulated state.
val modify : ('s -> 's) -> ('s, 'x, unit) t
Use modify f to produce a monad that applies f to the encapsulated state to obtain a new state value, and which returns the unit value as its intermediate result.
val field : ('s -> 'a) -> ('s, 'x, 'a) t
Use field f to produce a monad that returns the result of applying f to the value of the encapsulated state.
val down : ('s, 'x, unit) t -> 's -> ('x, 's) Cf_cmonad.t
Use down m s to produce a stateless continuation monad from a state-continuation monad and an initial state.
val lift : ('x, 'a) Cf_cmonad.t -> ('s, 'x, 'a) t
Use lift m to lift a stateless continuation monad into a state-continuation monad.