Module type
Class type

Generic contains the signature bits common to all state monad signatures.

State monads share the signatures of their builder functions with state transformers...

include State_transform_intf.Generic_builders
include State_transform_intf.Generic_types
type ('a, 's) t

t is the type of the state monad.

type 'a final

final is the type of returned results. In transformers, this becomes 'a Inner.t; otherwise, it becomes just 'a.

type 's state

state is the type used to represent the state outside of its monad. In S, 's state becomes x for some type x; in S2, 's state becomes 's.

val make : ('s state -> ('s state * 'a) final) -> ('a, 's) t

make creates a context-sensitive computation that can modify both the current context and the data passing through.

Specialised builders

val peek : ('s state -> 'a final) -> ('a, 's) t

peek creates a context-sensitive computation that can look at the current context, but not modify it.

val modify : ('s state -> 's state final) -> (Base.unit, 's) t

modify creates a context-sensitive computation that can look at and modify the current context.

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

return lifts a value or monad into a stateful computation. well as their runner functions...

include State_transform_intf.Generic_runners with type ('a, 's) t := ('a, 's) t and type 'a final := 'a final and type 's state := 's state
include State_transform_intf.Generic_types with type ('a, 's) t := ('a, 's) t with type 'a final := 'a final with type 's state := 's state
val run' : ('a, 's) t -> 's state -> ('s state * 'a) final

run' unfolds a t into a function from context to final state and result.

val run : ('a, 's) t -> 's state -> 'a final

run unfolds a t into a function from context to final result. To get the final context, use run' or call peek at the end of the computation.

...and fixed-point combinators.

include State_transform_intf.Fix with type ('a, 's) t := ('a, 's) t
val fix : f:(('a -> ('a, 's) t) -> 'a -> ('a, 's) t) -> 'a -> ('a, 's) t

fix ~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.