
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. Let's take the Writer monad documentation: all it says is: Inspired by the paper "Functional Programming with Overloading and Higher-Order Polymorphism", Mark P Jones (http://web.cecs.pdx.edu/~mpj/pubs/springschool.html) Advanced School of Functional Programming, 1995. SO WHAT? The best approach is the Part II of the "All About Monads" tutorial. There you have the almost ideal approach, except that the examples are just thrown there, with no step-by-step explanation. Of course one could copy, paste and run it, but this gives pretty much a "is it right?' feeling. Questions like "if a Reader is an application, why don't use a regular function instead?" or "what bind means for a State monad?". I will try to work on a "Part II" extended version on my vacations... maybe a WikiMonad... or MonadPedia... :-) After all, it is my duty as a haskell noob to write another monad tutorial! :D Cheers! -- Rafael Gustavo da Cunha Pereira Pinto Electronic Engineer, MSc.

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) 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

Jonathan Cast
On Tue, 2009-01-13 at 12:56 -0200, Rafael Gustavo da Cunha Pereira Pinto wrote:
Inspired by the paper "Functional Programming with Overloading and Higher-Order Polymorphism", Mark P Jones (http://web.cecs.pdx.edu/~mpj/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'?
I agree with Rafael here. The standard library documentation is insufficient. Pointing to nothing else than a paper is about the same as "RTFM", especially being "inspired" by a paper, there is really almost no information in the documentation. I wouldn't expect from an average programmer to read a whole paper to understand an everyday-use monad. Especially for newcomers to the purely functional world, even reading the introduction of a paper may well take an hour, which can be tiring and frustrating. There should be some basic information about the monad at least at the end of the documentation, as well as some well-thought usage examples. Greets, Ertugrul. -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://blog.ertes.de/

On Tue, 2009-01-13 at 07:51 -0800, Jonathan Cast 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) 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'?
We really shouldn't be expecting people to read papers as documentation
for standard libraries these days, however good they are. Like it or
not, most people find papers intimidating and the file formats are
non-standard for documentation (I can't be the only one who hates most
PDF docs, and most windows users wouldn't know where to start finding a
postscript viewer!).
Moving some of the info into the docs is a good idea. Doubly so as the
community's common pool of ideas has often moved on since the original
paper and much more accessible documentation can now be written.
On another note, perhaps there should be a note up somewhere asking
people not to cross-post between -beginners and -cafe? People on -cafe
don't realising they're responding to a beginner request, losing much of
the point of having -beginners.
--
Philippa Cowderoy

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?
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
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.htmlhttp://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.

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 declarations: 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). benedikt
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
mailto:jonathanccast@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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Wadler's examples are way better than the ones in the documentation. But
without his explanations of what he is doing, the examples alone are pretty
worthless.
I agree that all_about_monads could be a better source for the
documentation, at least for completeness. But even there I would consider
choosing simpler examples, like Wadler's expression evaluator.
On Tue, Jan 13, 2009 at 21:07, Benedikt Huber
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 declarations: 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).
benedikt
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
> 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.htmlhttp://web.cecs.pdx.edu/%7Empj/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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Rafael Gustavo da Cunha Pereira Pinto Electronic Engineer, MSc.

Jonathan Cast wrote:
On Tue, 2009-01-13 at 12:56 -0200, Rafael Gustavo da Cunha Pereira Pinto wrote:
Inspired by the paper "Functional Programming with Overloading and Higher-Order Polymorphism", Mark P Jones (http://web.cecs.pdx.edu/~mpj/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'?
To give a specific example, a few weeks ago I wanted an explanation of the 'pass' function and couldn't find it in that paper. Ganesh ============================================================================== Please access the attached hyperlink for an important electronic communications disclaimer: http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html ==============================================================================

On Tue, 2009-01-13 at 16:22 +0000, Sittampalam, Ganesh wrote:
Jonathan Cast wrote:
On Tue, 2009-01-13 at 12:56 -0200, Rafael Gustavo da Cunha Pereira Pinto wrote:
Inspired by the paper "Functional Programming with Overloading and Higher-Order Polymorphism", Mark P Jones (http://web.cecs.pdx.edu/~mpj/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'?
To give a specific example, a few weeks ago I wanted an explanation of the 'pass' function and couldn't find it in that paper.
Ganesh
Several years ago I documented all the (basic) monads in the mtl on the (old) wiki. http://web.archive.org/web/20030927210146/haskell.org/hawiki/MonadTemplateLi... In particular, http://web.archive.org/web/20030907203223/haskell.org/hawiki/MonadWriter To respond to the essential point of Rafael's initial claim, Wadler's papers "The Essence of Functional Programming" and/or "Monads for Functional Programming" have exactly what he wants. These are the papers that I recommend to anyone who is learning about monads. http://homepages.inf.ed.ac.uk/wadler/topics/monads.html Please, we do not need the 101st monad tutorial when there was an adequate one made almost two decades ago. While I'm not saying that this is the case here, I suspect that many people don't read those papers because 1) they haven't heard of them and 2) they are "papers" and thus couldn't possibly be readable and understandable (which also partially causes (1) as people just don't think to look for papers at all.)

I didn't knew Wadler's papers (I save all papers I read into a external USB
HD, so I can read them later!), and at a first glance it is really good.
Then again, instead of creating another "monad tutorial", what about a
Haskell monads reference guide, and some worked examples?
Some of this work could even be attached to the library documentation.
Regards
Rafael
On Tue, Jan 13, 2009 at 15:27, Derek Elkins
On Tue, 2009-01-13 at 16:22 +0000, Sittampalam, Ganesh wrote:
Jonathan Cast wrote:
On Tue, 2009-01-13 at 12:56 -0200, Rafael Gustavo da Cunha Pereira Pinto wrote:
Inspired by the paper "Functional Programming with Overloading and Higher-Order Polymorphism", Mark P Jones (http://web.cecs.pdx.edu/~mpj/pubs/springschool.htmlhttp://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'?
To give a specific example, a few weeks ago I wanted an explanation of the 'pass' function and couldn't find it in that paper.
Ganesh
Several years ago I documented all the (basic) monads in the mtl on the (old) wiki.
http://web.archive.org/web/20030927210146/haskell.org/hawiki/MonadTemplateLi... In particular, http://web.archive.org/web/20030907203223/haskell.org/hawiki/MonadWriter
To respond to the essential point of Rafael's initial claim, Wadler's papers "The Essence of Functional Programming" and/or "Monads for Functional Programming" have exactly what he wants. These are the papers that I recommend to anyone who is learning about monads. http://homepages.inf.ed.ac.uk/wadler/topics/monads.html
Please, we do not need the 101st monad tutorial when there was an adequate one made almost two decades ago. While I'm not saying that this is the case here, I suspect that many people don't read those papers because 1) they haven't heard of them and 2) they are "papers" and thus couldn't possibly be readable and understandable (which also partially causes (1) as people just don't think to look for papers at all.)
-- Rafael Gustavo da Cunha Pereira Pinto Electronic Engineer, MSc.

On Tue, 13 Jan 2009 19:35:57 +0100, Rafael Gustavo da Cunha Pereira Pinto
I didn't knew Wadler's papers (I save all papers I read into a external USB HD, so I can read them later!), and at a first glance it is really good.
Then again, instead of creating another "monad tutorial", what about a Haskell monads reference guide, and some worked examples?
Some of this work could even be attached to the library documentation.
Regards
Rafael
I have written a reference manual for the basic Haskell monad functions, "A Tour of the Haskell Monad functions". It contains a lot of examples. You can find it at: http://members.chello.nl/hjgtuyl/tourdemonad.html As far as I know, there is no reference guide for advanced monads, like the Reader, Writer and State monads. -- Regards, Henk-Jan van Tuyl -- http://functor.bamikanarie.com http://Van.Tuyl.eu/ --

I have written a reference manual for the basic Haskell monad functions, "A Tour of the Haskell Monad functions". It contains a lot of examples. You can find it at: http://members.chello.nl/hjgtuyl/tourdemonad.html
Wow! I like these examples. I'm a pragmatist, and although Haskell gave me the most intense joy I ever experienced with programming (and also frustrations ;-), I find it extremely difficult to learn it from research papers. But these small examples are exactly what I need, because my brain will easier recognize a pattern match with the specific examples, than with the abstract explanation (and I was pretty good at abstract algebra, but that's 20 years ago, and I filled these 2 decades with lots and lots of imperative and OO hacking ;-). I wish every function in every module in the documentation had an "examples" link next to the "source" link, or a link to examples on the wiki or something. I guess the smart computer scientists here will tell me that I need to lift my brain to learn to recognize abstract patterns, but I'm afraid this is not something that is given to all of us, certainly not in the short term. But I still want to enjoy Haskell, so keep the short examples coming :)
As far as I know, there is no reference guide for advanced monads, like the Reader, Writer and State monads.
-- Regards, Henk-Jan van Tuyl
-- http://functor.bamikanarie.com http://Van.Tuyl.eu/ --
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (9)
-
Benedikt Huber
-
Derek Elkins
-
Ertugrul Soeylemez
-
Henk-Jan van Tuyl
-
Jonathan Cast
-
Peter Verswyvelen
-
Philippa Cowderoy
-
Rafael Gustavo da Cunha Pereira Pinto
-
Sittampalam, Ganesh