[Haskell-cafe] Explaining monads

Lanny Ripple lanny at cisco.com
Tue Aug 14 10:55:11 EDT 2007


Having just gone through all the tutorials and things (again but 
this time I think it stuck) the Haskell community is on the wrong 
track as far as teaching Monads to new programmers.

If I were teaching addition and multiplication to children I 
wouldn't start with, "We'll begin by defining an algebraic 
structure named a "Group".  From there we'll expand our concept 
to a "Ring" and "Field".  A group is a set and a binary operator 
usually named "+" (or sometimes "*") such that...".

No no no.  You start with, "You all know how to count from one to 
10.  If we have 1 item and we 'add' another 1 item we have 2 
items.  We write this 1+1=2."

The tutorials seriously need to step back and start with 
something like, "To enforce order of evaluation we evaluate 
closures* returning a defined type.  The first closure will feed 
its result to the second which will in turn feed it's result to 
the third.  Since the third closure can't be evaluated without 
having the results from the second and first (and thus they had 
to be evaluated earlier in time) we get a defined evaluation 
sequence.  Here are some examples..."

(* Even using the word 'closure' is scary for those not familiar 
with them.)

Then, like "Monads For Functional Programming" (the paper that 
finally clicked Monads for me) you point out that evaluating all 
these closures returning a defined type in various ways form a 
structure (which you can then explain) and we can use that 
structure and change out the underlying effect(s) as needed.

Now of course if your new programmer has the the necessary 
background you can throw them in the deep end.  But don't do that 
to someone coming at the language from something like Java 
learned out of a business degree course.  (My background is a CS 
degree with math minor and it still took two go-s at Haskell 
before I got as far as understanding what folks were talking 
about with Monads.  Wish I had found Wadler's MFFP the first time 
around.)  Where are the shallow end tutorials?  (Don't get me 
wrong.  The tutorials are good but there is also a place for the 
"learn-by-rote with lots of examples" ones too.)

   $0.02,
   -ljr

PS - Not so much directed at Ronald's post but his was convenient 
to get me on my soapbox.

Ronald Guida wrote:
> My present goal is to understand monads well enough to be able to
> explain them to others.  I wonder if it's possible to create a
> tutorial that explains monads well enough so that they just "make
> sense" or "click" for people.
-- 
Lanny Ripple <lanny at cisco.com>
ScmDB / Cisco Systems, Inc.


More information about the Haskell-Cafe mailing list