package travesty

  1. Overview
  2. Docs
Monadically traversable containers

Install

dune-project
 Dependency

Authors

Maintainers

Sources

travesty-v0.6.1.tbz
sha256=9c7b3803620c54496a35983285242ec8e06a5efb1baa3523384d7184b7e9fab7
sha512=991646fe5bb899971d3f8c00432d4df6c45dbd81cbff885b28d30d9c228e5df61f1e8d61aadc164ec35c448093abb34fd7a7d571e1cdf4d3af25579bf400f167

doc/travesty/Travesty/State/index.html

Module Travesty.State

Haskell-style state monads.

State monads are a way to thread a modifiable, readable state record through a computation without resorting to mutability. At any point in a state-monad computation, we can peek at the present value of the state, or modify it, or do both.

We provide two signatures for state monads: 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). The former has a corresponding make functor; the latter has a direct implementation.

We also provide a functor To_S for fixing the state type in an arity-2 monad after the fact.

Relation to state transformers

Like in Haskell, state monads are a special case of state transformers, corresponding to the application of those transformers to the identity monad.

If you need to run stateful computations that can fail, or are partial, or non-deterministic, and so on, use state transformers instead.

Signatures

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

Manipulating state monads

module To_S (M : State_types.S2) (B : Base.T) : State_types.S with type state = B.t and type 'a t = ('a, B.t) M.t

To_S flattens a S2 into an S by fixing the state type to B.t.

Implementations and functors

module Make (B : Base.T) : State_types.S with type state = B.t

Make makes an S (state monad with fixed state type) from a single state type.

M2 is a basic implementation of S2 (state monad with variable state type).

OCaml

Innovation. Community. Security.