[Haskell-cafe] do

Denis Bueno dbueno at gmail.com
Mon Dec 3 16:09:30 EST 2007

On 03 Dec 2007, at 13:25 , Tim Newsham wrote:

>> Probably one should understand how to use monads before worrying  
>> about
>> the do-notation.  Here are some references:
> I don't totally agree.  You can teach monads to beginners just fine
> using the do-notation.  Unsuprisingly its very much like teaching
> monads using bind.  You describe a two line do-block as the basic
> building block for combining two actions into a single action:
>     do {
>         result1 <- act1
>         expr involving result1 building an act
>     }

By teaching >>= and return first in the context of monads, I think it  
encourages seeing 'do' primarily as syntactic sugar, instead of some  
mysterious construct in its own right.  This lets you apply  
everything you know about programming in pure, functional, typed  
programming (e.g. Haskell, SML, etc.) to monads, by seeing the type  
signature of >>= and return.  This, in turn, lets you conclude that  
monads are not mysterious at all, but simply a few operations whose  
types work in concert.  This doesn't mean you understand them, but it  
removes certain potential confusions.

If you learn 'do' first, there is a tendency to think of "using  
monads" and "using do" as synonymous, which they are not; and of  
thinking that 'do' is performing some sort of magic on your types  
(i.e. that you couldn't straightforwardly emulate 'do' with other  

When you're first learning monads, you're constantly suspicious of  
the mysterious, because of their name, their reputation, and their  
putative generality and power.  (I say 'putative' because when you're  
learning you don't yet know that it's true. =])

> I've had debates about what should be taught, and obviously not
> everyone agrees, but at the least, its possible and reasonable
> and understandable to teach do-notation first.

I don't think I can conclude that there are *no* reasons to teach the  
do-notation first.  I just think that it is more instructive to teach  
it later.

Please understand I'm a relative newbie in Haskell, so I would  
appreciate any comments on what I said above.  I'm still trying to  
learn. =]


More information about the Haskell-Cafe mailing list