Since partially applied functions are instances of the MonadReader
, why is the following code incorrect?
runReader (\x -> x + 2) 4
or even
runReader (\x -> pure $ x + 2) 4
Since partially applied functions are instances of the MonadReader
, why is the following code incorrect?
runReader (\x -> x + 2) 4
or even
runReader (\x -> pure $ x + 2) 4
Being an instance of MonadReader
allows you to use the "reader operations" (local
, ask
, asks
), but runReader
is explicitly for running a type of Reader
.
So for example, you can do this because of monadReaderFun
:
readerFunction :: Int -> Int
readerFunction = do
x <- ask
pure (x + 2)
But there's no need to "run" it, the way you do with a Reader
or ReaderT
typed value.