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 effect that combines the reader, writer and state effect, similar to the
MonadRWS
type class from the mtl
library.
Lazy and strict interpretations of the effect are available here: Control.Effect.RWS.Lazy and Control.Effect.RWS.Strict.
Synopsis
- class Monad m => RWS' tag r w s m | tag m -> r w s where
- type RWS r w s = RWS' G r w s
- ask :: RWS r w s m => m r
- local :: RWS r w s m => (r -> r) -> m a -> m a
- tell :: RWS r w s m => w -> m ()
- listen :: RWS r w s m => m a -> m (w, a)
- censor :: RWS r w s m => (w -> w) -> m a -> m a
- get :: RWS r w s m => m s
- put :: RWS r w s m => s -> m ()
- asks' :: forall tag r w s m a. RWS' tag r w s m => (r -> a) -> m a
- asks :: RWS r w s m => (r -> a) -> m a
- listens' :: forall tag r w s b m a. RWS' tag r w s m => (w -> b) -> m a -> m (b, a)
- listens :: RWS r w s m => (w -> b) -> m a -> m (b, a)
- gets' :: forall tag r w s m a. RWS' tag r w s m => (s -> a) -> m a
- gets :: RWS r w s m => (s -> a) -> m a
- modify' :: forall tag r w s m. RWS' tag r w s m => (s -> s) -> m ()
- modify :: RWS r w s m => (s -> s) -> m ()
- modifyStrict' :: forall tag r w s m. RWS' tag r w s m => (s -> s) -> m ()
- modifyStrict :: RWS r w s m => (s -> s) -> m ()
- newtype Separation m a = Separation {
- runSeparation :: m a
- runSeparatedRWS' :: (RWS' tag r w s `Via` Separation) m a -> m a
- runSeparatedRWS :: (RWS r w s `Via` Separation) m a -> m a
- tagRWS' :: forall new r w s m a. Via (RWS' G r w s) (Tagger G new) m a -> m a
- retagRWS' :: forall tag new r w s m a. Via (RWS' tag r w s) (Tagger tag new) m a -> m a
- untagRWS' :: forall tag r w s m a. Via (RWS' tag r w s) (Tagger tag G) m a -> m a
Tagged RWS Effect
class Monad m => RWS' tag r w s m | tag m -> r w s where Source #
An effect that adds the following features to a given computation:
- (R) an immutable environment (the "reader" part)
- (W) a write-only, accumulated output (the "writer" part)
- (S) a mutable state (the "state" part)
Gets the environment.
:: (r -> r) | The function to modify the environment. |
-> m a | The sub-computation to run in the modified environment. |
-> m a | The result of the sub-computation. |
Executes a sub-computation in a modified environment.
Produces the output w
. In other words, w
is appended to the accumulated output.
listen' :: m a -> m (w, a) Source #
Executes a sub-computation and appends w
to the accumulated output.
:: (w -> w) | The function which is applied to the output. |
-> m a | The sub-computation which produces the modified output. |
-> m a | The result of the sub-computation. |
Executes a sub-computation and applies the function to its output.
Gets the current state.
Replaces the state with a new value.
Instances
(Reader' tag r m, Writer' tag w m, State' tag s m) => RWS' (tag :: k) r w s (Separation m) Source # | |
Defined in Control.Effect.RWS ask' :: Separation m r Source # local' :: (r -> r) -> Separation m a -> Separation m a Source # tell' :: w -> Separation m () Source # listen' :: Separation m a -> Separation m (w, a) Source # censor' :: (w -> w) -> Separation m a -> Separation m a Source # get' :: Separation m s Source # put' :: s -> Separation m () Source # | |
Control (RWS' tag r w s) t m => RWS' (tag :: k) r w s (Via eff t m) Source # | |
Defined in Control.Effect.RWS | |
Handle (RWS' tag r w s) t m => RWS' (tag :: k) r w s (Via (RWS' tag r w s) t m) Source # | |
Defined in Control.Effect.RWS ask' :: Via (RWS' tag r w s) t m r Source # local' :: (r -> r) -> Via (RWS' tag r w s) t m a -> Via (RWS' tag r w s) t m a Source # tell' :: w -> Via (RWS' tag r w s) t m () Source # listen' :: Via (RWS' tag r w s) t m a -> Via (RWS' tag r w s) t m (w, a) Source # censor' :: (w -> w) -> Via (RWS' tag r w s) t m a -> Via (RWS' tag r w s) t m a Source # | |
(Monad m, Monoid w) => RWS' (tag :: k) r w s (RWST r w s m) Source # | |
Defined in Control.Effect.RWS | |
(Monad m, Monoid w) => RWS' (tag :: k) r w s (RWST r w s m) Source # | |
Defined in Control.Effect.RWS | |
(Monad m, Monoid w) => RWS' (tag :: k) r w s (RWST r w s m) Source # | |
Defined in Control.Effect.RWS.Strict | |
RWS' new r w s m => RWS' (tag :: k2) r w s (Tagger tag new m) Source # | |
Defined in Control.Effect.RWS ask' :: Tagger tag new m r Source # local' :: (r -> r) -> Tagger tag new m a -> Tagger tag new m a Source # tell' :: w -> Tagger tag new m () Source # listen' :: Tagger tag new m a -> Tagger tag new m (w, a) Source # censor' :: (w -> w) -> Tagger tag new m a -> Tagger tag new m a Source # |
Untagged RWS Effect
If you don't require disambiguation of multiple RWS effects (i.e., you only have one RWS effect in your monadic context), it is recommended to always use the untagged RWS effect.
Convenience Functions
Reader Convenience
If you don't require disambiguation of multiple RWS effects (i.e., you only have one RWS effect in your monadic context), it is recommended to always use the untagged functions.
:: forall tag r w s m a. RWS' tag r w s m | |
=> (r -> a) | The projection function to apply to the environment. |
-> m a | The result of the projection. |
Gets a specific component of the environment, using the provided projection function.
Writer Convenience
If you don't require disambiguation of multiple RWS effects (i.e., you only have one RWS effect in your monadic context), it is recommended to always use the untagged functions.
:: forall tag r w s b m a. RWS' tag r w s m | |
=> (w -> b) | The function which is applied to the output. |
-> m a | The sub-computation which produces the modified output. |
-> m (b, a) | The result of the sub-computation, including the modified output. |
Executes a sub-computation and applies the function to its output, thus adding an additional value to the result of the sub-computation.
State Convenience
If you don't require disambiguation of multiple RWS effects (i.e., you only have one RWS effect in your monadic context), it is recommended to always use the untagged functions.
gets' :: forall tag r w s m a. RWS' tag r w s m => (s -> a) -> m a Source #
Gets a specific component of the state, using the provided projection function.
modify' :: forall tag r w s m. RWS' tag r w s m => (s -> s) -> m () Source #
Modifies the state, using the provided function.
modifyStrict' :: forall tag r w s m. RWS' tag r w s m => (s -> s) -> m () Source #
Modifies the state, using the provided function. The computation is strict in the new state.
modifyStrict :: RWS r w s m => (s -> s) -> m () Source #
The untagged version of modifyStrict'
.
Interpretations
newtype Separation m a Source #
The separation interpreter of the RWS effect. This type implements the RWS'
type class by splitting the effect into separate Reader'
, Writer'
and
State'
effects which can then be interpreted individually.
When interpreting the effect, you usually don't interact with this type directly, but instead use one of its corresponding interpretation functions.
Separation | |
|
Instances
:: (RWS' tag r w s `Via` Separation) m a | The program whose RWS effect should be handled. |
-> m a | The program with its RWS effect handled. |
Runs the RWS effect via separation.
runSeparatedRWS :: (RWS r w s `Via` Separation) m a -> m a Source #
The untagged version of runSeparatedRWS'
.