July 2023
Intermediate to advanced
670 pages
17h 13m
English
In this chapter, we focused on two specific monad transformers: StateT and ExceptT. The transformers library provides several other commonly used monad transformers. One of the most common monad transformers is the ReaderT transformer. This monad transformer lets you write computations that have a read-only environment:
| | newtype ReaderT r m a = ReaderT {runReaderT :: r -> m a} |
The two basic operations for a ReaderT monad are ask, which fetches the value from the read-only environment, and local, which lets you run a ReaderT action with a modified local read-only environment. Their types are:
| | ask :: Monad m => ReaderT r m r |
| | local :: Monad m => (r -> r) -> ReaderT r m a -> ... |
Read now
Unlock full access