Can a (co)monad composed with itself be a (co)monad again?

45 Views Asked by At

I have very little categorical knowledge, my question comes mostly from programming, but I'm interested in the categorical solution of this problem.

Let's assume we have a monad $(T, \eta, \mu)$

Is $T^2$ automatically a monad? Will the following (for example) $$\eta' = \eta T ∘ \eta $$ and $$\mu' = {\mu}T ∘ \mu T^2 $$ suffice in $(T^2, \eta', \mu')$?

My intuition tells me, that according to monad laws $$\mu' \circ \eta' T^2 = {\mu}T ∘ \mu T^2 \circ \eta T^3 \circ \eta T^2 = \mu T \circ (\mu \circ \eta T)T^2 \circ \eta T^2 = \mu T \circ \eta T^ 2 = (\mu \circ \eta T)T = I$$ but this way $$\mu' \circ T^2\eta' = \mu T ∘ \mu T^2 \circ T^2 \eta T \circ T^2 \eta = \mu T ∘ (\mu T \circ T^2 \eta) T \circ T^2 \eta$$ and we don't have the $\mu T \circ T^2 \eta = I$ rule, so the right identity rule fails and therefore $(T^2, \eta', \mu')$ is not a monad.

I also have a feeling neither of the 5 other definitions of $\mu'$ will satisfy all the rules even if we change the definition of $\eta'$.

Is there a universal solution to this problem? Is it possible to turn $T^2$ into a monad by itself or is additional structure (like Haskell's Traversable T) required and which?

1

There are 1 best solutions below

0
On BEST ANSWER

Generally speaking, composing a monad $S$ with a monad $T$ does not produce a monad structure on their composite endofunctor $ST$: you require extra structure. This extra structure is known as a distributive law. A distributive law is a natural transformation $TS \Rightarrow ST$ satisfying some properties.

In the special case $S = T$, one might be tempted to take the identity natural transformation $TT \Rightarrow TT$. However, this is a distributive law if and only if $T$ is idempotent monad, which is a strong condition on $T$.