[Haskell-cafe] Lists vs. Monads

Cale Gibbard cgibbard at gmail.com
Fri Jul 15 12:32:49 EDT 2005

Interpretation A is correct. The type (constructor) of Lists gives a
monad together with return x = [x] and x >>= f = concatMap f x.

Interpretation B doesn't really work, because the monad interface does
not give one the ability to write "head" or "tail". You basically have
return (which gets you from an outside type into the monad), and bind
(which doesn't get you out of the monad, and doesn't permit direct
manipulation of the structure, so "tail" is generally not possible).

Lists give an especially good example of a monad though. Most (if not
all) monads can be viewed as containers of some type, with a broad
enough meaning of the word "container".

I wrote a little piece at
http://www.haskell.org/hawiki/MonadsAsContainers which goes over this
way of viewing them. Lists are a fundamental example. Near the end, I
show how things such as the state and reader monads can be viewed as
(perhaps a little unnatural) container types.

I think that both views (monads as containers and monads as semantics
for computation) are important to understanding monads and how they
relate to programming.

Hope this helps
 - Cale

On 15/07/05, Greg Buchholz <haskell at sleepingsquirrel.org> wrote:
>     Here's a question for the Haskell community that I've been wrestling
> with lately.  When we say "lists are monads" what does that mean?  I can
> see one of two things.  First the slightly superficial...
>   A.) Lists can be made members of the Monads class, and you can define
>       a couple of functions, "bind" and "return" that obey the Three Laws.
> ...or the more fundamental...
>   B.) Monads somehow define lists.  If you had a version of Haskell
>       without recursive data types you wouldn't be at a loss, because
>       you could always use monads to recreate lists.  Maybe "bind" would
>       replace the job of "cons" and "return" would replace "head" or
>       somesuch.
> I'm of the mind that A.) is the right interpretation, but I've seen the
> "lists are monads" meme mentioned enough that I sometimes question it.
> In fact, I had a hard time articulating B.) because I don't know what
> the other possibilies are. In case it isn't clear enough, here's another
> analogy...
>   A.) Insects are cold blooded animals.
> ...while that is 100% true, many other animals are cold blooded.  It
> doesn't get at the essence of what it means to be an insect.  Compare
> with a statment like...
>   B.) Insects are six-legged animals with an exoskeleton.
> ...which tells us a lot more about the fundamental nature of insects.
> Thanks,
> Greg Buchholz
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list