\documentclass{article}
\input{packages}
\input{def}

\lecture{Kleisli Categories}

\begin{document}
\maketitle

\begin{definition}[$\langle \ob{C}, \mo{m}, \mu, \noprf, \eta, \noprf \rangle$-Postmodule in a 2-Category $\cat{C}$]
A tuple $\langle \ob{R}, \mo{r}, \rho, \prf{d}, \prf{i} \rangle$ whose components have the following types:
\begin{framed}
\begin{description}
\item[Object $\ob{R}$:] $\cat{C}$
\item[Morphism $\mo{r}$:] $\ob{C} \mto \ob{R}$
\item[Action $\rho$:] $\mo{m} \cocomp \mo{r} \nto \mo{r}$
\item[Distributivity $\prf{d}$:] A proof that
\begin{tikzpicture}[baseline=0]
\node(c1) at (0,1) {$\ob{C}$};
\node(c2) at (1,-1) {$\ob{C}$};
\node(c3) at (3,-1) {$\ob{C}$};
\node(c4) at (4,1) {$\ob{R}$};
\draw[->] (c1) -- node[below left]{$\mo{m}$} (c2);
\draw[->] (c2) -- node[below]{$\mo{m}$} (c3);
\draw[->] (c3) -- node[below right]{$\mo{r}$} (c4);
\draw[->] (c2) -- node(f23){} node[above]{$\mo{r}$} (c4);
\draw[->] (c1) -- node(f123){} node[above]{$\mo{r}$} (c4);
\draw[double,double equal sign distance,-implies] (c3) -- node[below left]{$\rho$} (f23);
\draw[double,double equal sign distance,-implies] (c2) -- node[above left]{$\rho$} (f123);
\end{tikzpicture}
equals
\begin{tikzpicture}[baseline=0]
\node(c1) at (0,1) {$\ob{C}$};
\node(c2) at (1,-1) {$\ob{C}$};
\node(c3) at (3,-1) {$\ob{C}$};
\node(c4) at (4,1) {$\ob{R}$};
\draw[->] (c1) -- node[below left]{$\mo{m}$} (c2);
\draw[->] (c2) -- node[below]{$\mo{m}$} (c3);
\draw[->] (c3) -- node[below right]{$\mo{r}$} (c4);
\draw[->] (c1) -- node(f12){} node[above]{$\mo{m}$} (c3);
\draw[->] (c1) -- node(f123){} node[above]{$\mo{r}$} (c4);
\draw[double,double equal sign distance,-implies] (c2) -- node[below right]{$\mu$} (f12);
\draw[double,double equal sign distance,-implies] (c3) -- node[above right]{$\rho$} (f123);
\end{tikzpicture}
.\\
In other words,
\begin{tikzpicture}[baseline=1.5cm]
\node(f1) at (0,0) {$\mo{m}$};
\node(f2) at (2,0) {$\mo{m}$};
\node(f3) at (4,0) {$\mo{r}$};
\node(n1)[circle,draw] at (3,1) {$\rho$};
\node(n2)[circle,draw] at (2,2) {$\rho$};
\node(f123) at (2,3) {$\mo{r}$};
\draw[->] (f1) -- (n2);
\draw[->] (f2) -- (n1);
\draw[->] (f3) -- (n1);
\draw[->] (n1) -- node(f12)[above right]{$\mo{r}$} (n2);
\draw[->] (n2) -- (f123);
\node at (3.5,2.5) {$\ob{R}$};
\node at (3,.25) {$\ob{C}$};
\node at (1.75,.75) {$\ob{C}$};
\node at (.5,2) {$\ob{C}$};
\end{tikzpicture}
equals
\begin{tikzpicture}[baseline=1.5cm]
\node(f1) at (0,0) {$\mo{m}$};
\node(f2) at (2,0) {$\mo{m}$};
\node(f3) at (4,0) {$\mo{r}$};
\node(n1)[circle,draw] at (1,1) {$\mu$};
\node(n2)[circle,draw] at (2,2) {$\rho$};
\node(f123) at (2,3) {$\mo{r}$};
\draw[->] (f1) -- (n1);
\draw[->] (f2) -- (n1);
\draw[->] (f3) -- (n2);
\draw[->] (n1) -- node(f12)[above left]{$\mo{m}$} (n2);
\draw[->] (n2) -- (f123);
\node at (.5,2.5) {$\ob{C}$};
\node at (1,.25) {$\ob{C}$};
\node at (2.25,.75) {$\ob{C}$};
\node at (3.5,2) {$\ob{R}$};
\end{tikzpicture}
.
\item[Identity $\prf{i}$:] A proof that
\begin{tikzpicture}[baseline=(c1.base)]
\node(c1) at (0,0) {$\ob{C}$};
\node(c2) at (4,0) {$\ob{R}$};
\draw[->] (c1) .. controls (1.5,-1.5) and (2.5,-1.5) .. node(f1){} node[below]{$\mo{r}$} (c2);
\draw[->] (c1) .. controls (2.25,-1.5) and (2.25,1.5) .. node(f2){} node[right]{$\mo{m}$} (c1);
\draw[->] (c1) .. controls (1.5,1.5) and (2.5,1.5) .. node(f12){} node[above]{$\mo{r}$} (c2);
\draw[double,double equal sign distance,-implies] (c1) -- node[above]{$\eta$} (f2);
\draw[double,double equal sign distance,-implies] ($(f1.east) !.5! (c1.south)$) .. controls +(1.5,-.5) and ($(f12.south east) + (1,-1)$) .. node[right]{$\rho$} (f12.south east);
\end{tikzpicture}
equals
\begin{tikzpicture}[baseline=(c1.base)]
\node(c1) at (0,0) {$\ob{C}$};
\node(c2) at (1.5,0) {$\ob{R}$};
\draw[->] (c1) to[bend right=30] node[below]{$\mo{r}$} node(f1){} (c2);
\draw[->] (c1) to[bend left=30] node[above]{$\mo{r}$} node(f2){} (c2);
\draw[double,double equal sign distance] (f1) -- (f2);
\end{tikzpicture}
.\\
In other words,
\begin{tikzpicture}[baseline=1.5cm]
\node(f1) at (0,0) {$\mo{r}$};
\node(n1)[circle,draw] at (-1,1) {$\eta$};
\node(n2)[circle,draw] at (0,2) {$\rho$};
\node(f12) at (0,3) {$\mo{r}$};
\draw[->] (f1) -- ++(0,.5) .. controls +(0,.5) and ($(n2.south east) + (.5,-.5)$) .. (n2.south east);
\draw[->] (n1) -- node[above left]{$\mo{m}$} (n2);
\draw[->] (n2) -- (f12);
\node at (1,1) {$\ob{R}$};
\node at (-1.5,2.25) {$\ob{C}$};
\end{tikzpicture}
equals
\begin{tikzpicture}[baseline=1.5cm]
\node(f1) at (0,0) {$\mo{r}$};
\node(f2) at (0,3) {$\mo{r}$};
\draw[->] (f1) -- (f2);
\node at (-.5,1.5) {$\ob{C}$};
\node at (.5,1.5) {$\ob{R}$};
\end{tikzpicture}
.
\end{description}
\end{framed}
\end{definition}

\begin{remark}
A postmodule is more commonly called a right module.
\end{remark}

\begin{theorem}
For every monad $\langle \ob{C}, \mo{m}, \mu, \prf{d}, \eta, \prf{i} \rangle$, the tuple~$\langle \ob{C}, \mo{m}, \mu, \prf{d}, \prf{i} \rangle$ is a postmodule of that monad.
\end{theorem}

\begin{definition}[$\cat{Eff}(\alg{M})$ where $\alg{M} = \langle \cat{C}, M, \mu, \noprf, \eta, \noprf \rangle$ is a $\cat{CAT}$-Monad]
A category whose objects are the object of $\cat{C}$ and whose morphisms from $\ob{C}_1$ to $\ob{C}_2$ are the $\cat{C}$-morphisms from $\ob{C}_1$ to $M(\ob{C}_2)$.
Given $\mo{f} : \ob{C}_1 \mto \ob{C}_2$ and $\mo{g} : \ob{C}_2 \mto \ob{C}_3$ in $\cat{Eff}(\alg{M})$, their composition in $\cat{Eff}(\alg{M})$ is the $\cat{C}$-morphism $\mo{f} \cocomp M(\mo{g}) \cocomp \mu_{\ob{C}_3}$.
This composition is associative due to naturality and associativity of $\mu$.
Given an object $\ob{C}$, the identity morphism in $\cat{Eff}(\alg{M})$ is the $\cat{C}$-morphism $\eta_\ob{C}$.
This is an identity with respect to composition due to identity of $\eta$ with respect to $\mu$.
\end{definition}

\begin{remark}
$\cat{Eff}(\alg{M})$ is known as the Kleisli category of~$\alg{M}$.
\end{remark}

\begin{exercise}
Prove that $\cat{Eff}(\Set)$ is isomorphic to $\cat{Rel}$.
\end{exercise}

\begin{exercise}
Prove that there is a functor~$I : \cat{C} \mto \cat{Eff}(\alg{M})$ that maps $\ob{C}$ to $\ob{C}$ and $\mo{f}$ to the morphism whose corresponding $\cat{C}$-morphism is $\mo{f} \cocomp \eta$ (or equivalently $\eta \cocomp M(\mo{f})$).
Prove that there is a natural transformation $\varrho : M \cocomp I \nto I$ that maps $\ob{C}$ to the morphism whose corresponding $\cat{C}$-morphism is $\id_M(\ob{C})$.
Prove that $\langle \cat{Eff}(\alg{M}), I, \varrho, \noprf, \noprf \rangle$ is a $\alg{M}$-postmodule.
\end{exercise}

\begin{remark}
$I$ above is injective if and only if $\eta$ is a natural monomorphism, meaning $\eta_\ob{C}$ is a monomorphism for all~$\ob{C}$.
\end{remark}

\begin{exercise}
Prove that for any $\cat{CAT}$-monad $\alg{M}$ and $\alg{M}$-postmodule $\langle \cat{R}, R, \rho, \noprf, \noprf \rangle$, there is a unique functor $R' : \cat{Eff}(\alg{M}) \mto \cat{R}$ such that $R = I \cocomp R'$ and $\rho = \varrho \cdot R'$.
\end{exercise}

\begin{remark}
Given a 2-category~$\cat{C}$, one can construct an opetory with the same 0-cells and 1-cells and with a 2-cell for each 2-cell from the composition of the inputs to the output.
$\cat{1}$ is the opetory with one 0-cell~$\ob{C}$, one 1-cell~$\mo{m} : \ob{C} \mto \ob{C}$, and one 2-cell from $\mo{m}^n \nto \mo{m}$ for each $n : \N$.
A monad~$\alg{M}$ in $\cat{C}$ corresponds to a functor~$M$ of opetories from $\cat{1}$ to $\cat{C}$.
Let $\cat{1}_r$ be the operatory with two 0-cells~$\ob{C}$ and $\ob{R}$, two 1-cells~$\mo{m} : \ob{C} \mto \ob{C}$ and $\mo{r} : \ob{C} \mto \ob{R}$, and one 2-cell from $\mo{m}^n\mo{r}$ to $\mo{r}$ for each $n : \N$ and one 2-cell from $\mo{m}^n \nto \mo{m}$ for each $n : \N$.
There is a unique functor of opetories from $\cat{1}$ to $\cat{1}_r$, which we will call $I_r$.
An $\alg{M}$-postmodule~$\alg{R}$, then, corresponds to a functor~$R$ of opetories from $\cat{1}_r$ to $\cat{C}$ such that $I_r \cocomp R$ equals $M$.
\end{remark}

\begin{exercise}
Show that a monad morphism from $\alg{M}_1$ to $\alg{M}_2$ provides a functor from $\cat{Eff}(\alg{M}_1)$ to $\cat{Eff}(\alg{M}_2)$.
\end{exercise}

\end{document}
