Module Monads.Std.Monad.State

module State: sig .. end
The State Monad.

The state monad denotes a generic effectful computation. Unlike Writer and Reader the State monad can perform arbitrary transformations on state. However, the same as withReader, the State monad comes in two flavors - with a type of state fixed at module level, or with a type of state left to be a type variable. In both cases the type of state remains constant during the computation. There is no difference in implementation, these are just two different interfaces.


type ('a, 'e) storage 
an abstract storage
type ('a, 'e) state 
an abstract type of stateful computations. The type variable 'a denotes types of values and the type variable 'e denotes a type of the state (aka envionment, aka world).
module type S = sig .. end
The State Monad interface with a fixed environment.
module type S2 = sig .. end
module Multi: sig .. end
The Multi State monad.
include Monads.Std.Monad.State.S2
val eval : ('a, 'e) t -> 'e -> 'a
eval m is the same as run m >>| fst, i.e., it runs the computation and returns the computed value.
val exec : ('a, 'e) t -> 'e -> 'e
exec m is the same as run m >>| snd, i.e., it runs the computation and returns the final state.
module T1 (T : Std.T)  (M : Std.Monad.Monad) : sig .. end
module T2 (M : Std.Monad.Monad) : sig .. end
module Make (T : Std.T)  (M : Std.Monad.Monad) : S 
        with type 'a t := 'a T1(T)(M).t
         and type 'a m := 'a T1(T)(M).m
         and type 'a e := 'a T1(T)(M).e
         and type env := T.t
module Make2 (M : Std.Monad.Monad) : S2 
        with type ('a,'e) t := ('a,'e) T2(M).t
         and type 'a m     := 'a     T2(M).m
         and type ('a,'e) e := ('a,'e) T2(M).e