Home

Monad

In category theory, a monad on a category C is a triple (T, η, μ) in which T is an endofunctor T: C → C and η: Id_C → T and μ: T ∘ T → T are natural transformations. They satisfy the associativity and unit laws: μ ∘ Tμ = μ ∘ μT and μ ∘ Tη = μ ∘ ηT = id_T.

In functional programming, a monad is a design pattern that represents computations wrapped in a context, such

Common examples include Maybe/Option for computations that may fail, List for nondeterministic computations, IO for input/output

as
optional
values,
failure,
state,
or
I/O.
In
languages
like
Haskell,
a
monad
is
a
type
constructor
M
with
operations
return
::
a
->
M
a
and
(>>=)
::
M
a
->
(a
->
M
b)
->
M
b,
and
often
fmap
for
Functor.
The
monad
laws—left
identity,
right
identity,
and
associativity—guarantee
that
chaining
computations
is
predictable
and
composable.
actions,
State
for
threaded
state,
and
Reader
for
read-only
environments.
Monads
provide
a
uniform
interface
to
sequence
computations
with
effects
while
preserving
purity,
enabling
modular
construction
of
complex
behaviors.
Monads
are
frequently
combined
with
monad
transformers
to
stack
multiple
effects,
and
with
syntactic
sugar
like
do-notation
or
comprehensions
to
streamline
sequencing.