In , a monad is a that defines how functions, actions, inputs, and outputs can be used together to build , with the following organization:
- Define a data type, and how values of that data type are combined.
- Create functions that use the data type, and compose them together into actions, following the rules defined in the first step.
A monad may values of a particular , creating a new type associated with a specific additional , typically to handle special cases of the type. For example, the simple Maybe monad encapsulates which may have a , representing an , and automatically ensures that null values are not passed as arguments to functions that cannot handle them, serving as an alternative programming technique to throwing and catching when null values arise. Another example is the , where the empty list is a constant value of type List, and the operator binds a plain value as the head of a previous list.
The monad represents computations with a sequential structure: a monad defines what it means to chain operations together. This enables the programmer to build that process data in a series of steps (i.e. a series of actions applied to the data), in which each action is with the additional processing rules provided by the monad. A monad is defined by a return that creates values, and a bind operator used to link the actions in the pipeline; this definition must follow a set of called monad laws, which are needed for the composition of actions in the pipeline to work properly.
https://en.wikipedia.org/wiki/Monad_(functional_programming)