I am having difficulty in understanding the Reader Monad. My understanding from all the places I read, is that it allows to share a variable(Read Mode) to different function. Below is the implementation of two functions computation and samething (sorry for bad function names), one with Reader and one without it. I don't get the benefit using Reader.
module Moreunderstanding where
import Control.Monad.Reader
computation :: Reader Int Int
computation = do
a <- ask
b <- asks square
return (a + b)
square :: Int -> Int
square x = x ^ 2
samething:: Int -> Int
samething = do
a <- square
b <- id
return (a + b)
I am not sure what is that I am missing here.