Kleisli category

In category theory, a Kleisli category is a category naturally associated to any monad T. It is equivalent to the category of free T-algebras. The Kleisli category is one of two extremal solutions to the question: "Does every monad arise from an adjunction?" The other extremal solution is the Eilenberg–Moore category. Kleisli categories are named for the mathematician Heinrich Kleisli.

Formal definition
Let &lang;T, η, μ&rang; be a monad over a category C. The Kleisli category of C is the category CT whose objects and morphisms are given by
 * $$\begin{align}\mathrm{Obj}({\mathcal{C}_T}) &= \mathrm{Obj}({\mathcal{C}}), \\

\mathrm{Hom}_{\mathcal{C}_T}(X,Y) &= \mathrm{Hom}_{\mathcal{C}}(X,TY).\end{align}$$ That is, every morphism f: X &rarr; T Y in C (with codomain TY) can also be regarded as a morphism in CT (but with codomain Y). Composition of morphisms in CT is given by
 * $$g\circ_T f = \mu_Z \circ Tg \circ f : X \to T Y \to T^2 Z \to T Z$$

where f: X &rarr; T Y and g: Y &rarr; T Z. The identity morphism is given by the monad unit &eta;:
 * $$\mathrm{id}_X = \eta_X$$.

An alternative way of writing this, which clarifies the category in which each object lives, is used by Mac Lane. We use very slightly different notation for this presentation. Given the same monad and category $$C$$ as above, we associate with each object $$X$$ in $$C$$ a new object $$X_T$$, and for each morphism $$f\colon X\to TY$$ in $$C$$ a morphism $$f^*\colon X_T\to Y_T$$. Together, these objects and morphisms form our category $$C_T$$, where we define
 * $$g^*\circ_T f^* = (\mu_Z \circ Tg \circ f)^*.$$

Then the identity morphism in $$C_T$$ is
 * $$\mathrm{id}_{X_T} = (\eta_X)^*.$$

Extension operators and Kleisli triples
Composition of Kleisli arrows can be expressed succinctly by means of the extension operator (–)# : Hom(X, TY) &rarr; Hom(TX, TY). Given a monad &lang;T, η, μ&rang; over a category C and a morphism f : X &rarr; TY let
 * $$f^\sharp = \mu_Y\circ Tf.$$

Composition in the Kleisli category CT can then be written
 * $$g\circ_T f = g^\sharp \circ f.$$

The extension operator satisfies the identities:
 * $$\begin{align}\eta_X^\sharp &= \mathrm{id}_{TX}\\

f^\sharp\circ\eta_X &= f\\ (g^\sharp\circ f)^\sharp &= g^\sharp \circ f^\sharp\end{align}$$ where f : X &rarr; TY and g : Y &rarr; TZ. It follows trivially from these properties that Kleisli composition is associative and that &eta;X is the identity.

In fact, to give a monad is to give a Kleisli triple &lang;T, &eta;, (–)#&rang;, i.e. such that the above three equations for extension operators are satisfied.
 * A function $$T\colon \mathrm{ob}(C)\to \mathrm{ob}(C)$$;
 * For each object $$A$$ in $$C$$, a morphism $$\eta_A\colon A\to T(A)$$;
 * For each morphism $$f\colon A\to T(B)$$ in $$C$$, a morphism $$f^\sharp\colon T(A)\to T(B)$$

Kleisli adjunction
Kleisli categories were originally defined in order to show that every monad arises from an adjunction. That construction is as follows.

Let &lang;T, η, μ&rang; be a monad over a category C and let CT be the associated Kleisli category. Using Mac Lane's notation mentioned in the “Formal definition” section above, define a functor F: C &rarr; CT by
 * $$FX = X_T\;$$
 * $$F(f\colon X \to Y) = (\eta_Y \circ f)^*$$

and a functor G : CT &rarr; C by
 * $$GY_T = TY\;$$
 * $$G(f^*\colon X_T \to Y_T) = \mu_Y \circ Tf\;$$

One can show that F and G are indeed functors and that F is left adjoint to G. The counit of the adjunction is given by
 * $$\varepsilon_{Y_T} = (\mathrm{id}_{TY})^* : (TY)_T \to Y_T.$$

Finally, one can show that T = GF and &mu; = G&epsilon;F so that &lang;T, η, μ&rang; is the monad associated to the adjunction &lang;F, G, η, ε&rang;.

Showing that GF = T
For any object X in category C:
 * $$\begin{align}

(G \circ F)(X) &= G(F(X)) \\ &= G(X_T) \\ &= TX. \end{align}$$

For any $$f : X \to Y$$ in category C:
 * $$\begin{align}

(G \circ F)(f) &= G(F(f)) \\ &= G((\eta_Y \circ f)^*) \\ &= \mu_Y \circ T(\eta_Y \circ f) \\ &= \mu_Y \circ T\eta_Y \circ Tf \\ &= \text{id}_{TY} \circ Tf \\ &= Tf. \end{align}$$ Since $$(G \circ F)(X) = TX$$ is true for any object X in C and $$(G \circ F)(f) = Tf$$ is true for any morphism f in C, then $$G \circ F = T$$. Q.E.D.