[Haskell-cafe] Re: The problem with Monads...

Benedikt Huber benjovi at gmx.net
Tue Jan 13 18:07:02 EST 2009

Rafael Gustavo da Cunha Pereira Pinto schrieb:
> Yes, I've read it twice, and it is a nice explanation that "yes, the 
> reader monad is an application and is a monad". How do I use it? Why not 
> the function itself? How would the plumbing work in a real world example?
Hi Rafael,

First of all, I agree that the documentation for mtl should be improved.
Especially Control.Monad.RWS and Control.Monad.List really need some 
more information.

The documentation for the Reader and Identity monad are quite detailled 
though. They seem to be "inspired" by 
http://www.haskell.org/all_about_monads/, which also has documentation 
on Writer and Cont.

Control.Monad.List is a good example for the lack of documentation:
There is a single sentence at the beginning
 > "The List monad."
and then one declaration
 > newtype ListT m a = ListT { runListT :: m [a] }
while the important information is hidden as one of many instance 
 > Monad m => Functor (ListT m)
 > Monad m => MonadPlus (ListT m)

Btw, the quality of the examples in Control.Monad.Reader is debutable. 
 From Example 1:

 > -- The Reader monad, which implements this complicated check.
 > calc_isCountCorrect :: Reader Bindings Bool
 > calc_isCountCorrect = do
 >    count <- asks (lookupVar "count")
 >    bindings <- ask
 >    return (count == (Map.size bindings))

I think it is wrong (or weird at least) to call the function a 'Reader 
monad'; the name 'calc_isCountCorrect' is horrible too (because of the 
calc_ prefix),  Finally, implementing

 > isCountCorrect :: Bindings -> Bool
 > isCountCorrect bs = (bs Map.! "count") == Map.size bs

using the Reader monad will convince everybody _not_ to use it.

A suggestion: If license permits it, short versions of the articles on 
all_about_monads would make a great documentation for mtl (except for 
RWS and List, which are missing).


> BTW, the article is really great as an brief introduction to monad 
> transformers. For the whole concept of monads, my all time favorite is 
> "The Haskell Programmer's Guide to the IO Monad" by Stefan Klinger.
> Chapters 14 to 19 of "Real World Haskell" also have a good introduction 
> on the usage of the monads, but it lacks other monads, like the RWS or 
> the Continuation...
> See, that is my point. The mathematical concept of monads is very 
> palatable. The idea that monads are either patterns or structures to 
> hide computations in sequence is also very easy to see. But how do we 
> use them?
> Why should I use a Writer monad when I can use a (a,w) tuple?
> On Tue, Jan 13, 2009 at 13:51, Jonathan Cast <jonathanccast at fastmail.fm 
> <mailto:jonathanccast at fastmail.fm>> wrote:
>     On Tue, 2009-01-13 at 12:56 -0200, Rafael Gustavo da Cunha Pereira Pinto
>     wrote:
>      >
>      > Last night I was thinking on what makes monads so hard to take, and
>      > came to a conclusion: the lack of a guided tour on the implemented
>      > monads.
>     ...
>      > Inspired by the paper "Functional Programming with Overloading and
>      > Higher-Order Polymorphism",
>      >         Mark P Jones
>      > (http://web.cecs.pdx.edu/~mpj/pubs/springschool.html
>     <http://web.cecs.pdx.edu/%7Empj/pubs/springschool.html>)
>      >           Advanced School of Functional Programming, 1995.
>      >
>      > SO WHAT?
>     So have you read Jones' paper?  Or do you have a *concrete* explanation
>     of how it differs from your desired `guided tour'?
>     jcc
> -- 
> Rafael Gustavo da Cunha Pereira Pinto
> Electronic Engineer, MSc.
> ------------------------------------------------------------------------
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list