-
travesty
-
-
travesty.containers
-
-
travesty.core_kernel_exts
Library
Module
Module type
Parameter
Class
Class type
Haskell-style state transformers.
State transformers generalise state monads. They attach onto an existing monad, and allow the stateful computations to return and handle values inside that monad. For example, transforming On_error
provides stateful, potentially-failing computations.
We provide two signatures for state transformers: one corresponding to the situation where the state type is fixed at the module level (S), and one leaving the state type as part of the monad type (S2). Both have corresponding make functors.
We also provide a functor To_S for fixing the state type in an arity-2 monad after the fact.
Signatures
State_transform_intf contains the signatures for State_transform
.
include module type of State_transform_intf
module type Generic_types = sig ... end
Generic_types
contains generic versions of the types used in Generic_builders
and Generic_runners
.
module type Generic_builders = sig ... end
Generic_builders
contains generic versions of the 'builder' functions common to all state monad signatures.
module type Generic_runners = sig ... end
Generic_runners
contains generic versions of the 'runner' functions common to all state monad signatures.
module type Fix = sig ... end
Fix
contains the signature for fixpoint builders.
module type Generic = sig ... end
Generic
contains the signature bits common to all state transformers.
module type S = sig ... end
S
is the signature of state monad transformers with a fixed state type.
module type Basic = sig ... end
Basic
is the signature that must be implemented by state systems being lifted into S_transform
instances.
module type S2 = sig ... end
S2
is the signature of state transformers parametrised over both value and state types.
Manipulating state transformers
module To_S
(M : S2)
(B : Base.T) :
S
with type state = B.t
and type 'a t = ('a, B.t) M.t
and module Inner = M.Inner
To_S
flattens a S2
into an S
by fixing the state type to B.t
.