I would like to learn, how to use the Reader Monad. Unfortunately only a small amount of example code is available
I would like to create a Reader, where the environment and the retrived values are Int
. I defined the type like this:
type IntRead = Reader Int Int
The code I tried is this:
addStuff :: Reader Int Int
addStuff = do
a <- (*2)
b <- (+10)
return (a+b)
I get an error, because ReaderT
is expected. How to create a function like addStuff
using the Reader Monad? Where should I provide the environment to this function?
ask
:a <- (*2) <$> ask
– LazersmokeaddStuff
with an environment? With this code, I het an error:addStuff 10
– Iter AtorReader a b -> a -> b
. It's usually calledrunReader
. – Lazersmoke