package travesty

  1. Overview
  2. Docs
Legend:
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

For input and output signatures for this module's functors, see State_transform_types.

Manipulating state transformers

module To_S (M : State_transform_types.S2) (B : Base.T) : State_transform_types.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.

Functors for making state transformers

Make makes an S (state transformer with fixed state type) from a Basic.

module Make2 (M : Base.Monad.S) : State_transform_types.S2 with module Inner = M

Make2 makes an S2 (state transformer with variable state type) from a Monad.S.

OCaml

Innovation. Community. Security.