[Haskell-cafe] Explaining monads

Ronald Guida ronguida at mindspring.com
Mon Aug 13 23:53:33 EDT 2007


Ronald Guida wrote:
 > Given the question "What is a Monad", I would have to say "A Monad is
 > a device for sequencing side-effects."

peterv <bf3 at telenet.be> wrote:
 > "Side-effects" is a piece of linguistic cruft played fast-and-loose
 > by too many people in this game. "Sequencing" suffers the same
 > disease.

Gregory Propf wrote:
 > I made this mistake myself at first too.  It seems that the Monad =
 > "side effect machine" error is common to Haskell newbies.  Probably
 > to do with the fact that the first thing every programmer wants to
 > do is write a hello world program and for that you need the IO Monad
 > which requires some explanation of how a Monad can allow for side
 > effects (at least the IO Monad). - Greg

Eariler in this thread, I had a conversation with several people
regarding monads and arrows.  My goal was to try to come up with a
brief explanation.  I realized that "sequencing side-effects" is a
simplistic and incorrect view, so now I'm thinking in terms of DSELs.

I have heard that writing a monad tutorial is something people do when
they finally understand monads.  I interpret this observation to mean
that either (1) monads (and arrows) are just difficult things, or (2)
most of the existing explanations and tutorials are somehow inadequate
or incomplete.

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.

Here is the brief explanation I came up with:
 > Arrows and monads are abstract data types used to construct Domain
 > Specific Embedded Languages (DSELs) within Haskel.  A simple arrow
 > provides a closed DSEL.  A monad is a special type of arrow that
 > creates an open DSEL by allowing users to embed arbitrary Haskel
 > within it.

Is this an accurate explanation?  I hate to feed a fire, but is
"Domain Specific Embedded Language" a well-defined phrase, or is it
just another example of linguistic cruft? If DSEL is cruft, then is
there a better way to briefly explain monads and arrows?

Also, is this a /useful/ explanation, or have I simply hidden the
complexity by invoking the concepts of ADTs and DSELs?

-- Ron



More information about the Haskell-Cafe mailing list