package orsetto

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

The state monad and its operators.

Overview

The state monad represents the computation of transtions on its encapsulated state. It can be used as a basic element of a deterministic finite automaton.

Types
type ('s, 'r) t = 's -> 's * 'r

The state monad type.

module Basis : Cf_monad.Binary.Basis with type ('s, 'r) t := ('s, 'r) t
include Cf_monad.Binary.Profile with type ('s, 'r) t := ('s, 'r) 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.

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

Open Infix to include the infix 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.

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.

Operators
val nil : ('s, unit) t

A monad that returns unit and performs no operation.

val load : ('s, 's) t

A monad that returns the encapsulate state.

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

Use store s to produce a monad with s as the value of its encapsulated state.

val modify : ('s -> 's) -> ('s, 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 result when evaluated.

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

Use field f to produce a monad that returns the result of applying f to the value of the encapsulated state.

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

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

OCaml

Innovation. Community. Security.