Monday, March 30, 2009

Monads are Burritos

Earlier in the month, I gave at talk at the Lambda Lounge. The title was Monads are Burritos.

The slides are here. Some example code in Haskell is here. (I have provided examples both with and without the do-syntax: the latter is much cleaner and easier to use, but only once you understand the former. Be warned: the examples are rough, if you don't know Haskell).

The following are among my goals when it comes to talks:

  • I usually have a small set of ideas that I want to state, much like a thesis statement in an essay.
  • I strive to make the experience of attending a talk vastly different from the raw material on the slides. A goal is to reward those who come to my party. Imagine a 1920s ballroom on a Sunday morning. The slides should be like empty beer bottles, overturned tables, and bras hanging from the ceiling fan: mere artifacts indicating that something larger has taken place.
I may or may not have achieved these goals, but the result is the same: the slides will seem odd. So, here is an overview of my thesis points.

Monads are not Burritos

Brent Yorgey has a wonderful post on the tarpit of writing monad tutorials. Generally, someone goes off into the mountains for a few weeks, works hard, and has some kind of epiphany: say, for example, that monads are like burritos. Afterwards, they rave like a lunatic to puzzled listeners/readers.

To me, monads have nothing to do with burritos, but I liked the post so much that I named my talk after it.

Find your own Burrito

Some have challenged the FP world to explain monads in 2 sentences. I can't do that, but in 1993 I couldn't have done it for objects. In my freshman year, I couldn't have done it for recursion.

In other words, even if I did think that monads are burritos, it doesn't matter. You have to do the work and find out your own revelation. That is to say, you have to find your own burrito. Just as we did for polymorphism, encapsulation, inheritence, and so on.


The comic Demitri Martin has a puzzle wherein he wonders what the smartest thing anyone has said that starts with "Dude...". My favourite of his: "Dude, these are isotopes". (FWIW, he means "dude" here in a gender-neutral, skater-scene tone.)

I have two offerings (one of which was given at the talk):
  • Dude, a monad is a burrito, if a burrito is a functor-like object with a generic type, a sense of encapsulation, and the ability to combine small computations into larger ones!
  • Dude, a monad is a programmable semi-colon!

This post won't give examples, or even really try to explain the zen of monads. This is really intended as an explanation for the beer bottles and overturned tables. (Here are some more).

I may post some code later on, as a supplement to those who were there for the talk.

No comments: