Hello Café,
One thought occur to me recently when explaining the concept of Monad to non-haskellers: internally, all standard Monads are newtypes wrapping functions:
StateT is, WriterT is, ContT is. Even IO and ST are, both conceptually and in their implementation by GHC.
ParsecT (not part of mtl, but still) is. And so on...
So I'm saying that most of the time, we define a new monad:
- either by building a monad stack of existing transformers (thus "melting" their internal functions),
- or by creating a newtype containing a custom function.
Thinking thusly, >>= would then just be a special function composition operator: in the spirit of '.' but for a specific type of functions.
So my questions are:
- Is it reasonable to think like that, or are there too many monads that cannot be defined like that, and then contradict me?
- Is it reasonable to present monads to newcomers by saying : monads are basically always functions. 'return x' will then be a function that always return 'x' regardless of its input and >>= is a special composition for this occasion.
--
The ⊥ is a lie.