0

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
z1naOK9nu8iY5A
  • 903
  • 7
  • 22

1 Answers1

2

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.

gb.
  • 4,629
  • 1
  • 20
  • 19