Here's from someone who's still learning Haskell.

On Wed, Sep 01, 1999 at 03:24:48PM +0200, George Russell wrote:
> Thus all you 
> need to explain is "do" (which is in almost all respects identical to impure 
>sequencing 
> constructs in impure languages), and the IO typeconstructor.

I had many problems writing programs in the do notation until I understood
the underlying (>>=).  Why?  For example, in imperative languages I
can rewrite

         a <- b
         c <- f a
         
as 

        c <- f b
        
In Haskell I can't.  Why?  b is of type IO something, whereas f expects a
non-monadic argument.  This confused me greatly, until I started thinking
of do as syntactic sugar for (>>=).  Thus, while "do" does help someone
who knows (>>=) to visualize the operations, you can never use do with
plain imperative intutition: for example, you can't think of "a <- b"
as assignment (which is the immediate analogy for someone who does not
know monads well).  Therefore, even using "do" requires one to understand
the play with types and actions as values, and from there it's trivial
to get to (>>=).

-- 
%%% Antti-Juhani Kaijanaho % [EMAIL PROTECTED] % http://www.iki.fi/gaia/ %%%

                                  ""
                             (John Cage)


Reply via email to