Ok, using Haskell terminology and examples ...
Functional programming monad is a composition template for data types with type * -> * .
class Monad (m :: * -> *) where return :: a -> ma (>>=) :: ma -> (a -> mb) -> mb
(The class is larger than Haskell, but these are important parts.)
A data type is a monad if it can implement this interface while satisfying three conditions in the implementation. These are the “laws of the monad," and I will leave it to those old explanations for a full explanation. I summarize the laws, because " (>>= return) is an identical function, and (>>=) associative." It really is nothing more, even if it can be expressed more accurately.
And this is the whole monad. If you can implement this interface while retaining these behavioral properties, you have a monad.
This explanation is probably shorter than you expected. This is because the monad interface is very abstract. An incredible level of abstraction is part of why so many different things can be modeled as monads.
What is less obvious, as abstract as an interface, it allows you to generally simulate any control flow template, regardless of the actual implementation of the monad. That is why in the Control.Monad package in the GHC base library there are such combiners as when , forever , etc. And therefore, the ability to explicitly abstract from any monad implementation is powerful, especially with the support of the type system.
Carl Nov 22 2018-11-11T00: 00Z
source share