(Originally posted on stackoverflow, but I got no satisfying (for me) answer there.)
I'm a bit lost in Section 8.8 from Category Theory for Programmers.
The book reads
[…] the mapping that takes a pair of objects $a$ and $b$ and assigns to it the set of morphisms between them, the $hom$-set $C(a, b)$, is a functor.
I don't understand it. If a functor is something that can be mapped over, what does it mean to map on the mapping […]?
However, I tried to keep reading.
It is a functor from the product category $C^{op} × C$ to the category of sets, $Set$.
My understanding is that, as long as we talk of objects and not of morphisms, $C^{op} × C$ is not different from $C × C$. Indeed the book addresses that right now:
Let's define its action on morphisms. […]
and the rest of the paragraph can be made in drawing as follows
a f a'
┌┬──────┬┬┬── • <─────── • ──┬┬┬────────┬┐
││ │││ │││ ││
││C(a,b)│││ │││C(a',b')││
││ … │││ │││ … ││
││ │││ b g b' │││ ││
└┴──────┴┴┴─> • ───────> • <─┴┴┴────────┴┘
where it's clear that $g \cdot h \cdot f$ is in $C(a',b')$ for each $h$ from $C(a,b)$.
However, I can't really match this objects/morphisms/compositions with the statement at the beginning of the section and the one at the very end, therefore I don't get what this $hom$-functor is.
$\newcommand{\C}{\textsf{C}} \newcommand{\op}{\operatorname{op}} \newcommand{\Hom}{\operatorname{Hom}}$
Lets start with any category $\C$. We want to define the functor $\Hom$ as follows: $$\Hom: \C^{\op}\times \C \to \textsf{Set}$$ We first need to define it on objects. That's easy: $\Hom(X,Y)$ is by the definition the set of all morphism from $X$ to $Y$.
Next we need to define it on morphisms. But what exactly are morphisms in $\C^{\op} \times \C$? Well for a given pair of objects $(X,Y)$ and $(X',Y')$, a morphism $(X, Y) \to (X',Y')$ is actually a pair of morphisms $(f,g)$ where $f:X'\to X$ and $g:Y\to Y'$. Note the direction of arrows due to $\op$. Also you need to understand how composition works in $\C^{\op} \times \C$. If $(f,g)$ and $(f',g')$ are two morphisms then $$(f,g)\circ (f',g'):=(f'\circ f, g\circ g').$$ The different direction again comes from the $\op$.
And so given $(f,g)$ morphism, or equivalently $f$ and $g$ morphisms, we are somehow supposed to create another morphism (which in case of $\textsf{Set}$ is just a function) by going through $\Hom$. Meaning $\Hom(f,g)$ is supposed to be a function $\Hom(X,Y) \to \Hom(X',Y')$. Remember that $\Hom(X,Y)$ is a set, and thus we can consider functions between such sets. There's nothing really deep here. For example if $C(\mathbb{R})$ denotes the set of all continuous functions $\mathbb{R} \to \mathbb{R}$, then we can consider $p:C(\mathbb{R})\to C(\mathbb{R})$ given by $$p(f)(x)=f(x)+1.$$ Meaning it takes any continuous function and applies "$+1$" to it. It is a similar idea here, we are transforming morphisms and such transformation is a function itself.
Anyway how do we define $\Hom(f,g)$? Note that we can evaluate $\Hom(f,g)$ on any $\alpha:X\to Y$. So for a given morphism $\alpha:X\to Y$ we get that $\Hom(f,g)(\alpha)$ is supposed to be an element of $\Hom(X',Y')$, i.e. it is supposed to be a morphism $X'\to Y'$. And so given those four pieces of data we have: $f$, $g$, $\alpha$ and the expected output, there is only one real way to construct such morphism:
$$\Hom(f,g)(\alpha):=g\circ\alpha\circ f.$$
I encourage you to write down every object, morphism and composition to see why exactly it is well defined, and why we need that $\op$ (otherwise the composition is invalid, and actually there's no way to fix that).
With this we have that $\Hom$ is a functor. For example composition preserving goes like this: \begin{align} \Hom\big((f,g)&\circ(f',g')\big)(\alpha) = \\ &= \Hom(f'\circ f,g\circ g')(\alpha) = \\ &=g\circ g'\circ\alpha\circ f'\circ f= \\ &=g\circ \Hom(f',g')(\alpha)\circ f= \\ &=\Hom(f,g)\big(\Hom(f',g')(\alpha)\big). \end{align}
Note that $(f,g)\circ (f',g')=(f'\circ f,g\circ g')$ again due to $\op$. This gives us
$$\Hom\big((f,g)\circ(f',g')\big)=\Hom(f,g)\circ \Hom(f',g')$$
because $\alpha$ is arbitrary. Just like in the classical set theory if $f(g(x))=h(x)$ for all $x$ then we write $f\circ g=h$.
Also note that I use "$\circ$" symbol here in three different (but closely related) meanings: as a composition in $\C^{\op}\times \C$, as a composition in $\C$, and as a composition in $\textsf{Set}$.