So I come at this from a math background but I’ve always found these explanations to be overly complex. In the parlance of C++, I think of a monad as a template class T with the following properties:
1. For any class X, there is a canonical method
F: X -> T<X>
2. For any class X, there is a canonical method G: T<T<X>> -> T<X>.
3. For classes X and Y, and any method f: X -> Y,
there is a corresponding method “T<f>”: T<X> -> T<Y>.
—————-Here “any type” means any type that is compatible with the template.
And then there’s some additional rules which make all these methods compatible, based on the different ways of stacking nested T’s and the “canonical” maps you get. Admittedly there is some confusing accounting here, but I also think most natural ways of constructing the above three requirements are going to satisfy them anyway. For List and Maybe it’s fairly obvious what the above methods are.
I dunno, maybe I have it wrong and someone can correct my understanding.
replies(4):