module Cf_smonad:sig
..end
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.
type('s, 'a)
t ='s -> 'a * 's
module Op:sig
..end
( >>= )
binding operator for composition of state
monads.
val nil : ('s, unit) t
unit
and performs no operation.val return : 'a -> ('s, 'a) t
return a
to produce a monad that returns a
when evaluated.val load : ('s, 's) t
val store : 's -> ('s, unit) t
store s
to produce a monad with s
as the value of its encapsulated
state.val modify : ('s -> 's) -> ('s, unit) t
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
field f
to produce a monad that returns the result of applying f
to
the value of the encapsulated state.