# Module Cf_smonad

    module Cf_smonad: sig .. end

The state monad and its operators.

###### Overview

The state monad is provided here mostly for reference purposes. It is not actually used directly within the `cf` library. However, it is sometimes helpful to have an example of the state monad to use when lifting another monad into a new monad with state.

###### Overview

The state monad is provided here mostly for reference purposes. It is not actually used directly within the `cf` library. However, it is sometimes helpful to have an example of the state monad to use when lifting another monad into a new monad with state.

###### Types

    type ('s, 'a) t = 's -> 'a * 's

The state monad. Evaluate by calling it with an initial state.

###### Modules

    module Op: sig .. end

A module containing the `( >>= )` binding operator for composition of state monads.

###### Operators

    val nil : ('s, unit) t

A monad that returns `unit` and performs no operation.

    val return : 'a -> ('s, 'a) t

Use `return a` to produce a monad that returns `a` when evaluated.

    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 -> 'a) -> ('s, 'a) t

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