Copyright | (c) Michael Szvetits 2020 |
---|---|
License | BSD3 (see the file LICENSE) |
Maintainer | typedbyte@qualified.name |
Stability | stable |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
The state effect, similar to the MonadState
type class from the mtl
library.
Lazy and strict interpretations of the effect are available here: Control.Effect.State.Lazy and Control.Effect.State.Strict.
Synopsis
- class Monad m => State' tag s m | tag m -> s where
- type State s = State' G s
- get :: State s m => m s
- put :: State s m => s -> m ()
- state :: State s m => (s -> (s, a)) -> m a
- gets' :: forall tag s m a. State' tag s m => (s -> a) -> m a
- gets :: State s m => (s -> a) -> m a
- modify' :: forall tag s m. State' tag s m => (s -> s) -> m ()
- modify :: State s m => (s -> s) -> m ()
- modifyStrict' :: forall tag s m. State' tag s m => (s -> s) -> m ()
- modifyStrict :: State s m => (s -> s) -> m ()
- tagState' :: forall new s m a. Via (State' G s) (Tagger G new) m a -> m a
- retagState' :: forall tag new s m a. Via (State' tag s) (Tagger tag new) m a -> m a
- untagState' :: forall tag s m a. Via (State' tag s) (Tagger tag G) m a -> m a
Tagged State Effect
class Monad m => State' tag s m | tag m -> s where Source #
An effect that adds a mutable state to a given computation.
Gets the current state.
Replaces the state with a new value.
state' :: (s -> (s, a)) -> m a Source #
Updates the state and produces a value based on the current state.
Instances
Monad m => State' (tag :: k) s (StateT s m) Source # | |
Monad m => State' (tag :: k) s (StateT s m) Source # | |
State' tag s m => State' (tag :: k) s (Separation m) Source # | |
Defined in Control.Effect.RWS get' :: Separation m s Source # put' :: s -> Separation m () Source # state' :: (s -> (s, a)) -> Separation m a Source # | |
Handle (State' tag s) t m => State' (tag :: k) s (EachVia (State' tag s ': effs) t m) Source # | |
Find (State' tag s) effs t m => State' (tag :: k) s (EachVia (other ': effs) t m) Source # | |
Lift (State' tag s) t m => State' (tag :: k) s (EachVia ([] :: [Effect]) t m) Source # | |
Monad m => State' (tag :: k) s (RWST r w s m) Source # | |
(Monad m, Monoid w) => State' (tag :: k) s (RWST r w s m) Source # | |
Monad m => State' (tag :: k) s (RWST r w s m) Source # | |
State' new s m => State' (tag :: k2) s (Tagger tag new m) Source # | |
RWS' new r w s m => State' (tag :: k1) s (Tagger tag new m) Source # | |
Untagged State Effect
If you don't require disambiguation of multiple state effects (i.e., you only have one state effect in your monadic context), it is recommended to always use the untagged state effect.
Convenience Functions
If you don't require disambiguation of multiple state effects (i.e., you only have one state effect in your monadic context), it is recommended to always use the untagged functions.
gets' :: forall tag s m a. State' tag s m => (s -> a) -> m a Source #
Gets a specific component of the state, using the provided projection function.
modify' :: forall tag s m. State' tag s m => (s -> s) -> m () Source #
Modifies the state, using the provided function.
modifyStrict' :: forall tag s m. State' tag s m => (s -> s) -> m () Source #
Modifies the state, using the provided function. The computation is strict in the new state.
modifyStrict :: State s m => (s -> s) -> m () Source #
The untagged version of modifyStrict'
.
Tagging and Untagging
Conversion functions between the tagged and untagged state effect, usually used in combination with type applications, like:
tagState'
@"newTag" programretagState'
@"oldTag" @"newTag" programuntagState'
@"erasedTag" program