[Math] Simple show cases for the Yoneda lemma

ct.category-theoryexamples

I've been given a very simple motivating and instructive show case for the Yoneda lemma:

Given the category of graphs and a graph object $G$, seen as a quadruple $(V_G,\ E_G,\ S_G:E\rightarrow V,\ T_G:E \rightarrow V)$.

Consider $K_1$ and $K_2$, the one-vertex and the one-edge graph and the two morphisms $\sigma$ and $\tau$ from $K_1$ to $K_2$.

Now consider the graph $H$ with

  • $V_H = Hom(K_1,G)$
  • $E_H = Hom(K_2,G)$
  • $S_H(e) = e \circ \sigma: K_1 \rightarrow G$ for $e \in E_H$
  • $T_H(e) = e \circ \tau: K_1 \rightarrow G$ for $e \in E_H$

It can be easily seen that $H$ is isomorphic to $G$.

I have learned that a) the category of graphs is a presheaf category and that b) $K_1$, $K_2$ are precisely the representable functors.

Now I am looking for other simple motivating and instructive show cases.

By the way: Shouldn't such an show case be added to the Wikipedia entry on Yoneda's lemma?

Best Answer

If you program in a pure functional programming language like Haskell then the Yoneda lemma tells you that for any functor $F$, the types $F a$ and $\forall b . (a \rightarrow b) \rightarrow F b$ are isomorphic. (Restricting attention to computable total functions.) This really is a non-trivial statement and quite surprising when you first see it. Unfortunately it's tricky to explain without some CS backround.

Nonetheless I'll risk failure and try to explain a specific example when $F$ is the 'list' functor, assuming a little computing knowledge:

Fix a type $a$. Suppose you have a (polymorphic) Haskell function $f$ that for any type $b$ maps functions $g\colon a\rightarrow b$ into a list of elements of type $b$. Then $f$ is equal to a function that applies $g$ elementwise to some fixed list of elements of $a$. It's a powerful result. Just knowing the type of the function $f$ is enough to deduce significant detail about what it does. It can reduce the amount of work required to prove the correctness of programs.

The crucial thing that makes this work is that Haskell uses "parametric polymorphism". If you write a function that is polymorphic it's impossible to use specific knowledge about the type, you have to write your function generically to work with all possible types.

Related Question