package travesty
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=40ada5c475cfeba7d933eec133294d1b5ef5da6ce864c9746b2ce4ce49b5e3a4
md5=dc818d6b232f13edb388d25781cd99a2
doc/travesty/Travesty/State/index.html
Module Travesty.State
Source
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
State_intf contains the signatures for State
.
include module type of State_intf
Generic
contains the signature bits common to all state monad signatures.
S
is the signature of state monads parametrised over their value, but with a fixed state type.
Manipulating state monads
Implementations and functors
Make
makes an S
(state monad with fixed state type) from a single state type.