[Haskell-cafe] A Reader Monad Tutorial
Lee Duhem
lee.duhem at gmail.com
Sun Jun 28 03:00:46 EDT 2009
On Sun, Jun 28, 2009 at 12:41 AM, Henry Laxen<nadine.and.henry at pobox.com> wrote:
> Dear Group,
>
> If any of you are struggling with understanding monads, I've tried to put
> together a pretty through explanation of what is behind the Reader monad. If
> you're interested, have a look at:
>
> http://www.maztravel.com/haskell/readerMonad.html
>
Nice post.
I didn't find how to add comments on your blog, so I post them here:
>Areas of Confusion
>
> 1. What is the relationship between the Reader on the left hand side of the equals sign in the newtype definition and the Reader on the right hand side?
> 2. Why is there a Record field on the right hand side?
> 3. What is that r -> a doing there?
1) Reader on the left hand side be called a type constructor, Reader
on the right hand side be called a data constructor,
in Haskell 98 Report. You call them type definition and instance
constructor, respectively, I'm not sure it's a good idea, or
it is right.
bug in the explanation:
what you use to make something and instance of a Reader (left hand side)
-> what you use to make something an instance of a Reader (left hand side)
2) runReader be called a selector function in Haskell 98 Report.
3) (->) is a type constructor, so r -> a is a function type.
I used found 'instance Monad ((->) r)' hard to understand, but by
follow the hit given by Brent Yorgey, i.e. the data constructor for
type constructor (->) is called lambda abstraction, I found I can
understand them by type inference. I have written a post about how I
figure
it out, maybe you want take a look:
http://leeduhem.wordpress.com/2009/06/07/understanding-monad-instance-by-type-inference/
bug in the explanation after (Reader f1) >>= f2 = Reader $ \e ->
runReader (Reader b) e:
Reader b is a function that takes and e and returns a c,
-> Reader b is a function that takes an e and returns a c,
lee
More information about the Haskell-Cafe
mailing list