[Haskell-cafe] Question of a manual computation on Reader Monad.

Peter Cai newptcai at gmail.com
Sat Aug 25 09:57:48 EDT 2007

Hi all,

In order to improve my understanding of monad, I am trying to do some manual
computation on "Reader Monad" but I got some problem.

The computation is like this:

--instance Monad (Reader e) where
--    return a         = Reader $ \e -> a
--    (Reader r) >>= f = Reader $ \e -> f (r e) e

runReader (do { b <- Reader $ show; return b } )  -- This is the initial
expression, it should equals "show"

runReader (Reader $ show >>= \b -> return b)   -- remove do notion

runReader (Reader $ \e -> return( show e ) e)  -- apply the definition of

runReader (Reader $ \e -> (Reader $ \e1 -> show(e)) e)  -- apply the
definition of "return"

But the last expression is incorrect, and I don't know how to go on.

Could anyone explain this for me?

Thanks in advance!

Reference : http://www.haskell.org/all_about_monads/html/readermonad.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070825/ccdb6227/attachment-0001.htm

More information about the Haskell-Cafe mailing list