Safe Haskell | Trustworthy |
---|---|
Language | Haskell2010 |
Control.Eff.State.Strict
Description
Strict state effect
Synopsis
- data State s v where
- withState :: Monad m => a -> s -> m (a, s)
- get :: forall s (r :: [Type -> Type]). Member (State s) r => Eff r s
- put :: forall s (r :: [Type -> Type]). Member (State s) r => s -> Eff r ()
- runState :: forall s (r :: [Type -> Type]) a. s -> Eff (State s ': r) a -> Eff r (a, s)
- modify :: forall s (r :: [Type -> Type]). Member (State s) r => (s -> s) -> Eff r ()
- evalState :: forall s (r :: [Type -> Type]) a. s -> Eff (State s ': r) a -> Eff r a
- execState :: forall s (r :: [Type -> Type]) a. s -> Eff (State s ': r) a -> Eff r s
- data TxState (s :: k) = TxState
- withTxState :: forall s (r :: [Type -> Type]) a. Member (State s) r => a -> s -> Eff r a
- transactionState :: forall s (r :: [Type -> Type]) a. Member (State s) r => TxState s -> Eff r a -> Eff r a
- runStateR :: forall s (r :: [Type -> Type]) a. s -> Eff (Writer s ': (Reader s ': r)) a -> Eff r (a, s)
Documentation
State, strict
Initial design: The state request carries with it the state mutator function We can use this request both for mutating and getting the state. But see below for a better design!
data State s v where State :: (s->s) -> State s s
In this old design, we have assumed that the dominant operation is modify. Perhaps this is not wise. Often, the reader is most nominant.
See also below, for decomposing the State into Reader and Writer!
The conventional design of State
Instances
(MonadBase m m, LiftedBase m r) => MonadBaseControl m (Eff (State s ': r)) Source # | |
Handle (State s) r a (s -> k) Source # | Handle 'State s' requests |
Defined in Control.Eff.State.Strict Methods handle :: (Eff r a -> s -> k) -> Arrs r v a -> State s v -> s -> k Source # handle_relay :: forall (r' :: [Type -> Type]). (r ~ (State s ': r'), Relay (s -> k) r') => (a -> s -> k) -> (Eff r a -> s -> k) -> Eff r a -> s -> k Source # respond_relay :: (a -> s -> k) -> (Eff r a -> s -> k) -> Eff r a -> s -> k Source # | |
type StM (Eff (State s ': r)) a Source # | |
withState :: Monad m => a -> s -> m (a, s) Source #
Embed a pure value in a stateful computation, i.e., given an initial state, how to interpret a pure value in a stateful computation.
get :: forall s (r :: [Type -> Type]). Member (State s) r => Eff r s Source #
Return the current value of the state. The signatures are inferred
put :: forall s (r :: [Type -> Type]). Member (State s) r => s -> Eff r () Source #
Write a new value of the state.
Arguments
:: forall s (r :: [Type -> Type]) a. s | Initial state |
-> Eff (State s ': r) a | Effect incorporating State |
-> Eff r (a, s) | Effect containing final state and a return value |
Run a State effect
modify :: forall s (r :: [Type -> Type]). Member (State s) r => (s -> s) -> Eff r () Source #
Transform the state with a function.
evalState :: forall s (r :: [Type -> Type]) a. s -> Eff (State s ': r) a -> Eff r a Source #
Run a State effect, discarding the final state.
execState :: forall s (r :: [Type -> Type]) a. s -> Eff (State s ': r) a -> Eff r s Source #
Run a State effect and return the final state.
data TxState (s :: k) Source #
An encapsulated State handler, for transactional semantics The global state is updated only if the transactionState finished successfully
Constructors
TxState |
withTxState :: forall s (r :: [Type -> Type]) a. Member (State s) r => a -> s -> Eff r a Source #
Embed Transactional semantics to a stateful computation.
transactionState :: forall s (r :: [Type -> Type]) a. Member (State s) r => TxState s -> Eff r a -> Eff r a Source #
Confer transactional semantics on a stateful computation.
runStateR :: forall s (r :: [Type -> Type]) a. s -> Eff (Writer s ': (Reader s ': r)) a -> Eff r (a, s) Source #
A different representation of State: decomposing State into mutation (Writer) and Reading. We don't define any new effects: we just handle the existing ones. Thus we define a handler for two effects together.