[Haskell-cafe] Explaining monads

Sebastian Sylvan sebastian.sylvan at gmail.com
Tue Aug 14 13:11:17 EDT 2007

On 14/08/07, Dan Piponi <dpiponi at gmail.com> wrote:
> On 8/14/07, Sebastian Sylvan <sebastian.sylvan at gmail.com> wrote:
> > I like the very light weight analogy (which works for most practical
> > uses of monads) that a monadic action is a "recipe"
> Many introductory programming books present the idea of a program as a
> recipe. Here's a recipe for computing factorials:
> fact 0 = 1
> fact n = n*fact (n-1)
> Where do monads come in?

Well I would try to distinguish between code that we write to compute
values, and values which represent monadic actions when coming up with
analogies. You may wish to explain code as recipes too, but I think
your students would start getting confused if you overload the same
analogy for two different things.

The point was to find some real world analogy for "abstraction of an
action". A cooking recipe fits the bill pretty well. Everyone "gets"
that you can have a "model" of "making pancake batter" in the form of
a recipe, and that you can combine such recipes with other recipes or
store them in boxes or whatever. Once you're that far along, you're
half way there in teaching them enough to be able to use most monads
in practice.

Sebastian Sylvan
UIN: 44640862

More information about the Haskell-Cafe mailing list