So I'm told (->) r
is an instance of the Reader monad, but I can't seem to find any concrete examples of how this is supposed to work. I want to use this without having to explicitly wrap some of my code in a Reader
import Control.Monad.Reader
testOne :: Reader String String
testOne = do
env <- ask
return $ "Hello, " ++ env
testTwo :: String -> String
testTwo = do
env <- ask
return $ "G'day, " ++ env
Running runReader testOne "there"
works fine, but running runReader testTwo "mate"
fails spectacularly with the following message:
Couldn't match type ‘String -> String’
with ‘ReaderT [Char] Data.Functor.Identity.Identity a’
Expected type: Reader [Char] a
Actual type: String -> String
So what am I missing here?