package orsetto

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

The state-continuation monad and its operators.

Overview

The state-continuation monad is the composition of the continuation monad and the state monad: a function for passing intermediate results from continuation context to continuation context with an encapsulated state value at each stage.

Types
type ('s, 'x, 'r) t = ('s -> 'x, 'r) Cf_cmonad.t

The state-continuation monad type.

module Basis : Cf_monad.Trinary.Basis with type ('s, 'x, 'r) t := ('s, 'x, 'r) t
include Cf_monad.Trinary.Profile with type ('s, 'x, 'r) t := ('s, 'x, 'r) t

Module inclusions from Cf_monad_core and Cf_seqmonad.

include Cf_monad.Core.Trinary.Profile with type ('p, 'q, 'r) t := ('p, 'q, 'r) t
val return : 'r -> ('p, 'q, 'r) t

Use return a to apply the binding to a.

val bind : ('p, 'q, 'a) t -> ('a -> ('p, 'q, 'b) t) -> ('p, 'q, 'b) t

Use bind m f to bind f to the value returned by m.

val map : ('p, 'q, 'a) t -> f:('a -> 'b) -> ('p, 'q, 'b) t

Use map m f to return the result of applying f to the value returned by m.

module Infix : Cf_monad_core.Trinary.Infix with type ('p, 'q, 'r) t := ('p, 'q, 'r) t

Open Infix to include the infix monad operators.

val disregard : ('p, 'q, 'r) t -> ('p, 'q, unit) t

Use disregard m to ignore the value returned by m and apply the unit value to the bound function.

include Cf_seqmonad.Functor.Trinary with type ('p, 'q, 'r) t := ('p, 'q, 'r) t
val collect : ('p, 'q, 'r) t Seq.t -> ('p, 'q, int * 'r list) t

Use collect s to bind in sequence every monad value in the finite sequence s and collect all the returned values. Returns (n, s) where n is the number of values collected and s is the list of values in reverse order, i.e. from last collected to first collected. Never returns and exhausts all memory if s never terminates.

val serial : ('p, 'q, unit) t Seq.t -> ('p, 'q, unit) t

Use serial s to bind in sequence every monad value in the sequence s.

Operators
val nil : ('s, 'x, unit) t

A monad that returns unit and performs no operation.

val init : 'x -> ('s, 'x, 'r) t

Use init x to produce a monad that discards the current intermediate context and passes x into the continuation.

val cont : ('x -> 'x) -> ('s, 'x, unit) t

Use cont f to produce a monad that applies f to the current intermediate context and passes the result into the continuation.

val load : ('s, 'x, 's) t

A monad that returns the encapsulate state.

val store : 's -> ('s, 'x, unit) t

Use store s to produce a monad with s as the 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.

val field : ('s -> 'r) -> ('s, 'x, 'r) t

Use field f to produce a monad that applies f to the encapsulated state and returns the result.

val downC : ('s, 'x, unit) t -> 's -> ('x, 's) Cf_cmonad.t

Use downC m s to lower m initialized with state s into a continuation monad that returns the final state.

val downS : ('s, 'x, unit) t -> 'x -> ('s, 'x) Cf_smonad.t

Use downS m x to lower m initialized with context x into a state monad that returns the final context without modifying the encapsulated state.

val liftC : ('x, 'r) Cf_cmonad.t -> ('s, 'x, 'r) t

Use liftC m to lift a stateless continuation monad m into a state-continuation monad.

val liftS : ('s, 'r) Cf_smonad.t -> ('s, 'x, 'r) t

Use liftS m to lift a state monad m into a state-continuation monad.

val eval : ('s, 'x, unit) t -> 's -> 'x -> 'x

Use eval m s to evaluate the state-continuation monad m with initial state s to produce a function from an initial context to a final context.

val bridge : 'x -> ('x -> 'y) -> ('s, 'x, unit) t -> ('s, 'y, unit) t

Use bridge x f m to lower the state-continuation monad m, then bridge with the initial context x and a map function f, and finally lift the result to another state-contination monad, one that evaluates m using the state bridged from the result monad.

OCaml

Innovation. Community. Security.