'A Reader monad for multiple arguments?
Is there an equivalent to the Reader monad that's equivalent to a -> b -> c rather than just a -> b. I know I could do (a, b) -> c but I'm not sure that's going to be very ergonomic.
Solution 1:[1]
The only way to make that a monad is by wrapping it which may not be what you're after. The instance can be derived
{-# Language DerivingVia #-}
import Control.Monad.Reader
newtype Reader2 a b c = Reader2 (a -> b -> c)
deriving (Functor, Applicative, Monad, MonadFix, MonadReader a)
via ReaderT a ((->) b)
If you derive Representable it witnesses the isomorphism between Reader2 a b c and (a, b) -> c
index :: Reader2 a b c -> ((a, b) -> c)
tabulate :: ((a, b) -> c) -> Reader2 a b c
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Iceland_jack |
