Monads in Clojure
Since I was also exploring Clojure, an interesting new dialect of Lisp that strongly encourages a purely functional programming style (but doesn't enforce it), I decided to explore monads by writing a monad library for Clojure. My experience is that monads are quite useful in Clojure as well, and that once you get used to monads, you see occasions for using them almost everywhere. If you have been hesitating to tackle monads seriously, I can only encourage you to go on!
I have also written a monad tutorial for Clojure programmers, which I published on the OnClojure blog. It consists of four parts:
- Part 1 introduces the concept of monads and illustrates it with the identity and maybe monads.
- Part 2 explains the importance of
m-result
using the sequence monad as an example. It also covers the monad laws. - Part 3 is about m-zero and m-plus, and explains the state monad.
- Part 4 covers the probability monad and monad transformers.
I hope that this tutorial facilitates a first contact with monads for those who are more familiar with Lisp syntax than with Haskell syntax.