Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
State as an algebraic effect
The runState
handler calls each continuation exactly once.
It is compatible with single-shot continuations.
Synopsis
- data State (s :: Type) :: AEffect where
- get :: z :> zz => Handler (State s) z -> Eff zz s
- put :: z :> zz => Handler (State s) z -> s -> Eff zz ()
- putL :: z :> zz => Handler (State s) z -> s -> Eff zz ()
- modify :: z :> zz => Handler (State s) z -> (s -> s) -> Eff zz ()
- modifyL :: z :> zz => Handler (State s) z -> (s -> s) -> Eff zz ()
- runState :: s -> (forall z. Handler (State s) z -> Eff (z :& zz) a) -> Eff zz (a, s)
- evalState :: s -> (forall z. Handler (State s) z -> Eff (z :& zz) a) -> Eff zz a
- execState :: s -> (forall z. Handler (State s) z -> Eff (z :& zz) a) -> Eff zz s
Operations
get :: z :> zz => Handler (State s) z -> Eff zz s Source #
Get the current state. Call the Get
operation.
put :: z :> zz => Handler (State s) z -> s -> Eff zz () Source #
Put a new state. Call the Put
operation.
This function is strict.
modify :: z :> zz => Handler (State s) z -> (s -> s) -> Eff zz () Source #
Modify the state.
This function is strict in the modified state.
Handlers
:: s | Initial state |
-> (forall z. Handler (State s) z -> Eff (z :& zz) a) | Stateful computation |
-> Eff zz (a, s) |
Run a stateful computation from the given starting state.