Mathematical motivation/intuition for monads The internet is filled with intuitive explanations of what monads are in the context of programming. This is very frustrating as i don't have programming background and i'm trying to learn about monads with only mathematical background. I understand their definition but i don't see what they're useful for nor have any intuition for it.
 A: You can check out my old posts A monad is just a monoid in the category of endofunctors, what’s the problem? and Monads are idempotents for two different ways of motivating the definition of a monad. Here I can briefly summarize the contents of the second post. In any category, let $f : x \to y$ be a morphism. Recall that

*

*if $f$ admits a left inverse $g : y \to x$ (a map such that $g \circ f = \text{id}_x$) then $x$ is said to be a retract of $y$. The motivating example to keep in mind here is that in an abelian category this says exactly that $x$ is a direct summand of $y$.

*with the above hypotheses, the composite $m = f \circ g : y \to y$ is an idempotent, and $x$ can be recovered from $m$ as either the equalizer $\text{eq}(m, \text{id}_y)$ or the coequalizer $\text{coeq}(m, \text{id}_y)$; this is called splitting an idempotent. You can see the "The facts of life about idempotents and retracts" section of my old post Tiny objects for more on this.

*in a category in which all idempotents split (which is guaranteed in particular if either equalizers or coequalizers always exist), splitting idempotents establishes a natural bijection between retracts of an object and idempotent endomorphisms of it.

So idempotents control the "nice subobjects" of an object. The story of monads can be thought of as a categorification of this. Now let $F : C \to D$ be a functor (or more generally a morphism in a $2$-category, since monads make sense in this generality). A motivating example to keep in mind is the forgetful functor from $\text{Grp}$ to $\text{Set}$. Now:

*

*if $F$ admits a left adjoint $G : D \to C$ then the composite $M = F \circ G : D \to D$ is a monad, and if $F$ is furthermore monadic then $C$ can be recovered from $M$ as the Eilenberg-Moore category of $M$.

*if $F$ admits a left adjoint, then $F$ is fully faithful (and hence $C$ is a full subcategory of $D$) iff the monad $M$ is idempotent (meaning that the multiplication $M \circ M \to M$ is an isomorphism). In this case $F$ is automatically monadic and exhibits $C$ as a reflective subcategory of $D$, and this establishes an equivalence between reflective subcategories of $D$ and idempotent monads on $D$.

So monads can be thought of as categorified idempotents, with the multiplication $M \circ M \to M$ categorifying the idempotent law $m^2 = m$. Taking the Eilenberg-Moore category is a categorification of taking the fixed points of an idempotent (which is computed by the equalizer above), and for idempotent monads this construction controls the reflective subcategories which are categorified retracts, while for general monads this construction controls a much more general class of category mapping to $D$.
It turns out (and this is not at all obvious) that many categories are monadic over $\text{Set}$ in the sense of admitting monadic forgetful functors to $\text{Set}$; this includes in particular categories of algebraic structures such as groups, rings, and modules, and the relevant monads here encode the operations in such structures. This is one of the standard ways of introducing monads in a category-theoretic context but it hides how general they are. See, for example, my old MO answer here.
Computer scientists are interested in monads for quite a different reason; what they want to consider is the Kleisli category associated to a monad instead. So they will motivate monads using Kleisli composition. In terms of the above analogy the Kleisli category categorifies the coequalizer $\text{coeq}(m, \text{id}_y)$. For example there is a monad called the List monad, which to a category theorist is the monad whose Eilenberg-Moore category is the category of monoids, but which to a computer scientist is the monad whose Kleisli category allows you to describe and meaningfully compose functions which return a list of outputs rather than a single output.
A: Let me just add a third explanation, which is perhaps less useful from an advanced standpoint but more useful for a first motivation.
Theories of abstract algebra are traditionally given in terms of some finite number of operations and some finite number of laws they satisfy, such as the multiplication, unit, identity laws, and associativity law of a monoid.
However, there are actually infinitely many operations defined on a monoid, for instance the operation that sends $(x_1,x_2,x_3,x_4)$ to $x_1x_2x_3x_4.$ In fact it's possible to define a monoid structure on $S$ without singling out the binary multiplication or the unit by defining a function $\alpha: S^*\to S$ from the free monoid on $S$ back to $S$ giving the product of any string of elements of $S,$ including the empty string to define the identity. All that needs to be true to get a monoid is that $\alpha$ sends singleton strings to their sole entry and that $$\alpha(x_{11}\ldots x_{1n_1}x_{21}\ldots x_{2n_2}\ldots x_{m1}\ldots x_{mn_m})=\alpha(\alpha(x_{11}\ldots x_{1n_1})\alpha(x_{21}\ldots x_{2n_2})\ldots \alpha(x_{m1}\ldots x_{mn_m})).$$
It's easier to read this in terms of commutative diagrams involving the natural concatenation operation $S^{**}\to S^*$ than in terms of elements.
So, if you want to generalize abstract algebra, rather than going via model theory, where you define a first-order theory in terms of function symbols and relation symbols and well-formed formulae and so on, you can go via category theory by saying that an "algebraic theory" of some sort requires a way of defining a new set $TS$ from any set $S,$ representing the gadget that's free on $S,$ and coming with a map $T^2S\to TS$ for every $S$ representing the natural operation on the free gadget, plus a map $S\to TS$ showing how everything in $S$ lives inside the object free on $S.$ Make everything functorial and natural, and add a couple of reasonable axioms, and you've defined a monad; imitate the unbiased conception of a monoid above, and you've got algebras for the monad. In this way, we find there are monads for every familiar kind of object in abstract algebra, but also for structures like compact Hausdorff spaces that don't seem algebraic at all on a first look.
Thus studying monads on the category of sets alone gives you some very broad, yet still useful, generalization of abstract algebra, while you can immediately define a monad on any category you like, (or even in some 2-category other than the 2-category of small categories...) to generalize even much further, to things like algebraic gadgets equipped with a topology.
A: I only know the categorical part of monads, so I cannot connect it with the monads in programming, but you seem to be disinterested in that anyway.
My intuition for monads is that they provide a convenient setting to do universal algebra in the following sense. The most elementary while useful algebraic structure one can think of is that of a monoid ie. a set with associative and unital multiplication. This thing admits a very easy categorification into a monoid object in a monoidal category. In the same way we can define how a monoid acts on a set we can categorify how a monoid object acts on an object in our monoidal category. This is already pretty nice, since we have for example a definition of a topological monoid acting continuously on a topological space, without having to explicitly write down any continuity conditions. But I digress.
It is important to note that for a monoid object $M$ in some monoidal category $(\mathscr{C},\otimes)$ the functor $M\otimes-:\mathscr{C}\rightarrow\mathscr{C}$ gives rise to a monoid in the monoidal category $(\operatorname{End}(\mathscr{C}),\circ)$. We can rewrite the conditions of an $M$-action on an object $X$ into how the functor $M\otimes-$ behaves on evaluation at $X$. The cool thing about this reformulation is that we eliminated the need for the tensor $\otimes$ on $\mathscr{C}$. Indeed, writing down the axioms we see that we nowhere really use that the functor $M\otimes -$ is of this specific form. This leads us to the definition of a monad on $\mathscr{C}$. In other words, any category $\mathscr{C}$ lives inside the monoidal category $(\operatorname{End}(\mathscr{C}),\circ)$ and a monad on $\mathscr{C}$ is just a monoid object in $\operatorname{End}(\mathscr{C})$.
