Perhaps monads offer a better way, but I don't really get them yet ...
What are Monads?
I think Leibniz invented the term monad to describe some kind of indivisible fundamental entity in his philosophy: Presumably the term atom was too Greek for him. Anyway: I do not mean philosophical monads, or biological monads, or mathematical -- category theory -- monads (although now we are getting warmer).
Right now I mean computational monads, the ones so beloved of Haskell programmers, but potentially of use elsewhere.
A monad is a family of types M t, based on a polymorphic type constructor M, with functionsThis definition gave me flashbacks to Pure Mathematics Honours (4th year University) where I encountered some classes so abstract as to seem totally detached from reality: "Hello Banach Spaces and Algrebras!"
return :: t -> M t
(>>=) :: M t -> (t -> M u) -> M u
return a >>f = f a
m >>= return = m
m >>= (\a -> (f a) >>=g) = (m >>= f) >>= g
How to get it
But having survived a mathematics education and having a ridiculously high sense of self-efficacy I know how to get through this kind of obstacle. There are two methods:
- Abstractions first: Treat this as a game where the rules are given, and play with them until they become familiar and seem natural.
- Empirical approach: Walk in the footsteps of the discoverers by building some practical experience first, so that the abstractions begin to make sense.
You Could Have Invented Monads! (And Maybe You Already Have)
which seems to be helping, and belongs to the latter camp.
More later ...