[Haskell-cafe] Monad explanation

Jonathan Cast jonathanccast at fastmail.fm
Wed Feb 4 15:24:23 EST 2009


On Wed, 2009-02-04 at 22:16 +0200, Tymur Porkuian wrote:
> For me, the key to understanding monads was that monad is "a value
> that know how to apply functions to itself". Or, more correctly, a
> container that knows how to apply functions to whatever is inside it.

Close.  (Monads are not `values' but types, but I'll let that slide).

Remembering that all Haskell functions take a single argument, but we
use currying to support an arbitrary number of arguments, we can arrange
the Monad type class hierarchy like this:

* Functor: A functor F allows a single function to be applied to a
single F value.  Multiple arguments (or none) are not supported; the
definition of application does what you probably *don't* want if the
function returns an F value itself.
* Applicative: An applicative functor A allows a function of n arguments
(for n >= 0) to be applied to n A values.  However, the definition of
application does what you probably *don't* want if the function returns
an A value itself.
* Monad: A monad M allows a function of n arguments (for n >= 0) to be
applied to n M values; in addition, if the function returns an M value
itself, you can combine that result with the arguments in a sensible
way.

jcc




More information about the Haskell-Cafe mailing list