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