# What actually are Categories?

## 1. A class of objects

The class of objects is the primary defining element of any category.

These objects can basically be anything from "things" like the number 1 up to other categories, so a category of categories.

Notation

For a category $$\mathcal{K}$$, $$Ob(\mathcal{K})$$ or alternatively $$\lVert\mathcal{K}\rVert$$ denotes the class of objects in $$\mathcal{K}$$.

Example

As an example let's use the category of lists $$\mathcal{L}$$:

The following applies:

$Ob(\mathcal{L}) \Leftrightarrow \lVert\mathcal{L}\rVert = \mathbb{L}$

where $$\mathbb{L}$$ is the set of all lists.

The class of objects in the category of lists therefore is the set of all lists, so far so trivial.

## 2. Morphisms

As a seemingly cryptical term, morphisms describe what is called a function in calculus.

A morphism (from greek morphé - form/shape) therefore is something that 'reshapes' one thing into something else.

A morphism always relates to two sets, called domain and co-domain.

Notation

A morphism $$f$$ would usually be written as

$$f:\mathbb{A}\rightarrow\mathbb{B}$$

where $$\mathbb{A}$$ is called the domain of $$f$$ and $$\mathbb{B}$$ is called the co-domain of $$f$$.

Example

We define the increment-morphism $$+1$$ as follows:

$$+1:\mathbb{Z}\rightarrow\mathbb{Z}$$

$$+1: n\mapsto n+1$$

Domain and co-domain are both the integers $$\mathbb{Z}$$ .

Because domain and co-domain are identical in our example, we call $$+1$$ an "endomorphism".

## 3. Identity-morphism

The identity-morphism (or just identity) is, as the name suggests a morphism. The property that makes it special is simply, that it maps its object to itself.

Notation

The identity is noted as $$Id_{\mathcal{X}}$$ and the following applies

$$\forall x\in\lVert\mathcal{X}\rVert(Id_{\mathcal{X}}:x\mapsto x)$$

So "For all ($$\forall$$) objects in $$\mathcal{X}$$ the identity maps the object to itself".

## 4. The composition

The composition $$\circ$$ is a central component in category-theory and describes the possibility to combine (compose) morphisms. The composition of two morphisms produces a new morphism as a result.

Notation

The composition of two morphisms $$f$$ and $$g$$ is noted as follows

$$f:\mathbb{A}\rightarrow\mathbb{B}$$

$$g:\mathbb{B}\rightarrow\mathbb{C}$$

$$g\circ f:\mathbb{A}\rightarrow\mathbb{C}$$

We say "$$g$$ composed $$f$$".

Associativity

One requirement that category-theory makes for the composition is that it's associative.

That means, that the order of operations must not have an influence on the result, or more formal:

Les $$f$$, $$g$$ and $$h$$ be morphisms in $$\mathcal{K}$$,

$$f\circ (g\circ h)\Leftrightarrow (f\circ g)\circ h$$ applies.

Example

Let $$half$$ be the morphism, which maps a whole number to its half.

Let in addition $$floor$$ be the morphism, that maps a real number to the next lower integer.

It follows

$$half:\mathbb{Z}\rightarrow\mathbb{Q}$$

$$floor:\mathbb{R}\rightarrow\mathbb{Z}$$

with $$\mathbb{Q}\subset\mathbb{R}$$

$$floor\circ half:\mathbb{Z}\rightarrow\mathbb{Z}$$ applies

$$floor$$ composed $$half$$ is therefore an endomorphism.

## Preview

Next time we will look at functors and see why many types present in Kotlin are functors.