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 reader effect, similar to the MonadReader
type class from the mtl
library.
Synopsis
- class Monad m => Reader' tag r m | tag m -> r where
- type Reader r = Reader' G r
- ask :: Reader r m => m r
- local :: Reader r m => (r -> r) -> m a -> m a
- reader :: Reader r m => (r -> a) -> m a
- asks' :: forall tag r m a. Reader' tag r m => (r -> a) -> m a
- asks :: Reader r m => (r -> a) -> m a
- runReader' :: forall tag r m a. r -> (Reader' tag r `Via` ReaderT r) m a -> m a
- runReader :: r -> (Reader r `Via` ReaderT r) m a -> m a
- tagReader' :: forall new r m a. Via (Reader' G r) (Tagger G new) m a -> m a
- retagReader' :: forall tag new r m a. Via (Reader' tag r) (Tagger tag new) m a -> m a
- untagReader' :: forall tag r m a. Via (Reader' tag r) (Tagger tag G) m a -> m a
Tagged Reader Effect
class Monad m => Reader' tag r m | tag m -> r where Source #
An effect that adds an immutable state (i.e., an "environment") to a given computation. The effect allows to read values from the environment, pass values from function to function, and execute sub-computations in a modified environment.
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.
:: (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.
Instances
Monad m => Reader' (tag :: k) r (ReaderT r m) Source # | |
Reader' tag r m => Reader' (tag :: k) r (Separation m) Source # | |
Defined in Control.Effect.RWS ask' :: Separation m r Source # local' :: (r -> r) -> Separation m a -> Separation m a Source # reader' :: (r -> a) -> Separation m a Source # | |
Handle (Reader' tag r) t m => Reader' (tag :: k) r (EachVia (Reader' tag r ': effs) t m) Source # | |
Find (Reader' tag r) effs t m => Reader' (tag :: k) r (EachVia (other ': effs) t m) Source # | |
Control (Reader' tag r) t m => Reader' (tag :: k) r (EachVia ([] :: [Effect]) t m) Source # | |
Monad m => Reader' (tag :: k) r (RWST r w s m) Source # | |
(Monad m, Monoid w) => Reader' (tag :: k) r (RWST r w s m) Source # | |
Monad m => Reader' (tag :: k) r (RWST r w s m) Source # | |
Reader' new r m => Reader' (tag :: k2) r (Tagger tag new m) Source # | |
RWS' new r w s m => Reader' (tag :: k1) r (Tagger tag new m) Source # | |
Untagged Reader Effect
If you don't require disambiguation of multiple reader effects (i.e., you only have one reader effect in your monadic context), it is recommended to always use the untagged reader effect.
Convenience Functions
If you don't require disambiguation of multiple reader effects (i.e., you only have one reader effect in your monadic context), it is recommended to always use the untagged functions.
:: Reader' tag r 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.
Interpretations
:: r | The initial environment. |
-> (Reader' tag r `Via` ReaderT r) m a | The program whose reader effect should be handled. |
-> m a | The program with its reader effect handled. |
Runs the reader effect.
Tagging and Untagging
Conversion functions between the tagged and untagged reader effect, usually used in combination with type applications, like:
tagReader'
@"newTag" programretagReader'
@"oldTag" @"newTag" programuntagReader'
@"erasedTag" program