State_transform.Make2
Make2
makes an S2 (state transformer with variable state type) from a Monad.S
.
include State_transform_types.Generic
with type ('a, 's) t := ('a, 's) t
and type 's state := 's
with module Inner = M
include State_transform_types.Generic_builders
with type 'a final := 'a
with type ('a, 's) t := ('a, 's) t
with type 's state := 's
include State_transform_types.Generic_types
with type 'a final := 'a
with type ('a, 's) t := ('a, 's) t
with type 's state := 's
val make : ('s -> 's * 'a) -> ('a, 's) t
make
creates a context-sensitive computation that can modify both the current context and the data passing through.
val peek : ('s -> 'a) -> ('a, 's) t
peek
creates a context-sensitive computation that can look at the current context, but not modify it.
val modify : ('s -> 's) -> (Base.unit, 's) t
modify
creates a context-sensitive computation that can look at and modify the current context.
val return : 'a -> ('a, 's) t
return
lifts a value or monad into a stateful computation.
module Inner = M
Inner
is the monad to which we're adding state.
State transformers have the same runner signatures as state monads, but lifted into the inner monad.
include State_transform_types.Generic_runners
with type ('a, 's) t := ('a, 's) t
and type 'a final := 'a Inner.t
and type 's state := 's
include State_transform_types.Generic_types
with type ('a, 's) t := ('a, 's) t
with type 'a final := 'a Inner.t
with type 's state := 's
val run' : ('a, 's) t -> 's -> ('s * 'a) Inner.t
run'
unfolds a t
into a function from context to final state and result.
val run : ('a, 's) t -> 's -> 'a Inner.t
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.
include State_transform_types.Fix with type ('a, 's) t := ('a, 's) t