This is a summary of the course ``Algebra des Programmierens'' taught by Prof.\ Dr.\ Stefan Milius in the winter term 2023/2024 at the FAU~\footnote{Friedrich-Alexander-Universität Erlangen-Nürnberg}.
The course is based on~\cite{poll1999algebra} with~\cite{adamek1990abstract} as a reference for category theory.
Goal of the course is to develop a mathematical theory for semantics of data types and their accompanying proof principles. The chosen environment is the field of category theory.
Programs work with data that should ideally be organized in a useful manner.
A useful representation for data in functional programming is by means of \emph{algebraic data types}.
Some basic data types (written in Haskell notation) are
\begin{minted}{haskell}
data Bool = True | False
data Nat = Zero | Succ Nat
\end{minted}
These data types are declared by means of constructors, yielding concrete descriptions how inhabitants of these types are created.
\emph{Parametric data types} are additionally parametrized by another data type, e.g.\
\begin{minted}{haskell}
data Maybe a = Nothing | Just a
data Either a b = Left a | Right b
data List a = Nil | Cons a (List a)
\end{minted}
Such data types (parametric or non-parametric) usually come with a principle for defining functions called recursion and in richer type systems (e.g.\ in a dependently typed setting) with a principle for proving facts about recursive functions called induction.
Equivalently, every function defined by recursion can be defined via a \emph{fold}-function which satisfies an identity and fusion law, which replace the induction principle. Let us now consider two examples of data types and illustrate this.
The type of natural numbers comes with a fold function $foldn : C \rightarrow(Nat \rightarrow C)\rightarrow Nat \rightarrow C$ for every $C$, defined by
\begin{alignat*}{2}
& foldn\;c\;h\;zero && = c \\
& foldn\;c\;h\;(suc\;n) && = h\;(foldn\;c\;h\;n)
\end{alignat*}
\begin{example} Let us now consider some functions defined in terms of $foldn$.
\begin{itemize}
\item$iszero : Nat \rightarrow Bool$ is defined by
\[iszero = foldn\;true\;false!\]
\item$plus : Nat \rightarrow Nat \rightarrow Nat$ is defined by
We will now look at the $List$ type and examine it for similar properties. Let us start with the fold function $foldr : C \rightarrow(A \rightarrow C \rightarrow C)\rightarrow List\;A \rightarrow C$, which is defined by