package orsetto

  1. Overview
  2. Docs
On This Page
  1. Overview
  2. Types
Legend:
Library
Module
Module type
Parameter
Class
Class type

The continuation monad and its operators.

Overview

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.

Types
type ('x, 'a) t = ('a -> 'x) -> 'x

The continuation monad: a function for passing intermediate results from continuation context to continuation context.

module Basis : Cf_monad.Binary.Basis with type ('x, 'a) t := ('x, 'a) t
include Cf_monad.Binary.Profile with type ('x, 'a) t := ('x, 'a) t

Module inclusions from Cf_monad_core and Cf_seqmonad.

include Cf_monad.Core.Binary.Profile with type ('m, 'r) t := ('m, 'r) t
val return : 'r -> ('m, 'r) t

Use return a to apply the binding to a.

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

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

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

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

val product : ('m, 'a) t -> ('m, 'b) t -> ('m, 'a * 'b) t

Use product a b to return the monoidal product of a and b.

module Affix : Cf_monad_core.Binary.Affix with type ('m, 'r) t := ('m, 'r) t

Open Affix to include the affix monad operators.

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

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

module Infix = Affix

Deprecated module alias.

include Cf_seqmonad.Functor.Binary with type ('m, 'r) t := ('m, 'r) t
val collect : ('m, 'r) t Seq.t -> ('m, 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 : ('m, unit) t Seq.t -> ('m, unit) t

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

val nil : ('x, unit) t

A monad that returns unit and performs no operation.

val init : 'x -> ('x, 'a) t

Use init x to discard the current context and pass x into the continuation.

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

Use cont f to apply f to the current context and pass the result into the continuation.

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

Use eval m to evaluate the continuation monad, which produces a function from an initial context to a final context.

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

Use bridge x f m as a shortcut for init (f (eval m x)).

OCaml

Innovation. Community. Security.