State.M2SourceM2 is a basic implementation of S2 (state monad with variable state type).
include Base.Monad.S2Same as Infix, except the monad type has two arguments. The second is always just passed through.
include Generic
with type ('a, 's) t := ('a, 's) t
and type 's state := 's
and type 'a final := 'aState monads share the signatures of their builder functions with state transformers...
include State_transform_intf.Generic_builders
with type ('a, 's) t := ('a, 's) t
with type 's state := 's
with type 'a final := 'ainclude State_transform_intf.Generic_types
with type ('a, 's) t := ('a, 's) t
with type 's state := 's
with type 'a final := 'amake creates a context-sensitive computation that can modify both the current context and the data passing through.
peek creates a context-sensitive computation that can look at the current context, but not modify it.
modify creates a context-sensitive computation that can look at and modify the current context.
...as well as their runner functions...
include State_transform_intf.Generic_runners
with type ('a, 's) t := ('a, 's) t
and type 'a final := 'a
and type 's state := 'sinclude State_transform_intf.Generic_types
with type ('a, 's) t := ('a, 's) t
with type 'a final := 'a
with type 's state := 'srun' unfolds a t into a function from context to final state and result.
...and fixed-point combinators.
include State_transform_intf.Fix with type ('a, 's) t := ('a, 's) tfix ~f init builds a fixed point on f.
At each step, f is passed a continuation mu and a value a. It may choose to return a recursive application of mu, or some value derived from a.
To begin with, f is applied to mu and init.