What Does Monad Mean?

Tony Morris


This presentation is intended for the November 2009 meeting of the Brisbane Functional Programming Group http://www.meetup.com/Brisbane-Functional-Programming-Group-BFG/.

The monad concept will be presented to an audience with the assumption of knowledge of the generics concept of either the Java or C# programming languages or some other form of parametric polymorphism. The concept will be presented in a way with the objective of supplying enough understanding to apply the practical implications and will not address the underlying mathematics or category theory.

The monad concept has attracted much mysticism, misunderstanding and mythology, which will also be addressed.

Questions and comments should be forwarded to Tony Morris Appendix B, Tony Morris - PGP Key.

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License Appendix C, Licence.

Table of Contents

Monads are a hack for working with I/O in the real world
Monads are only for functional or esoteric programming languages
Monads make my program impure
A quick note on terminology
Monad laws
Type constructors and kinds
Higher-order Polymorphism
So what is a Monad then?
It's a fluffy cloud
Produced by a sonic boom
Monad metaphors are stupid
First let's pretend that Java/C# are practical
Finished staring?
Monads and more monads
More examples
Other examples include
So what, why do I care?
Repetition is for solving non-problems using clumsy languages
And it's not just monads
C#, LINQ Query Comprehensions and Monads
C# 3.0
Syntax sugar
Scala for-comprehensions and Monads
Transforming side-effects using monads
Suppose a program in a typical language
Change the syntax
More changes
More fun
Special Thanks
A. Code Examples
B. Tony Morris - PGP Key
C. Licence


Moggi first described monads for use in structuring programs [MoggiMonads1988]. Philip Wadler and Simon Peyton-Jones have worked further with the concept on introducing them to purely functional programming languages.

It is often said that monads are specific to functional programming. This is not true. Indeed, the term functional programming is itself quite a misnomer. It's simply practical programming and the thesis is composition and abstraction (see [WhyFP]). Monads are used in every single programming language. The only distinction is whether or not the user is aware of the fact.

This presentation will set aside the myths and present you with a concrete understanding of a rather simple concept that is easy to understand, but with far reaching implications. If the objectives of this presentation are met, you will be equipped to take advantage of this concept in your every-day programming and explore those implications further.