Previously: Natural transformation as a basis of control
In this article the mystery behind the language name choice is going to be finally revealed.
Diagrams again?
So, Yoneda lemma states the following:
Given any natural transformations from Hom Functor
Hom[a,-]
to FunctorT
, you can evaluate it atidentity[a]
to get a point inT[a]
.
Flipping parameters
But probably code representation would be more suitable for us? Let’s get the snippet from a previous article:
map[+]: hom a o `AR_` into (t a) (t o)
`yo` : t a `AR_` into (hom a o) (t o)
We will use just an Arrow instead into
placeholder here:
map[+]: hom a o `AR_` t a `AR__` t o
`yo` : t a `AR_` hom a o `AR__` t o
We can observe that everything we are doing here is just flipping arguments!
Another way to keep this correspodence in mind is to memorize such a natural isomorphism:
hom a o -> t o <====> t a
In Я all Yoneda forms with flipped arguments for functor mappings are derived via just one Natural transformation instance.
Continuations
Another perspective for better perceiving Yoneda lemma is a concept many engineers are familiar with - continuations. In simple words, continuations is a way to pybass control to another function which is usually gets into scope as a function parameter.
Compare a regular function declaration:
function f (arg) { return res }
… with another one, but in continuation passing style:
function f (arg) { return function(k) { return k(res) } }
It’s obvious for us that these two representations are isomorphic. You can keep this case in mind as an example of Yoneda lemma - but don’t forget that the latter is more powerful.
Yo for Yoneda, Ya for …?
Ah yeah, about naming… At first I wanted to call this language Yo
due to using Yoneda to improve syntactic constructions. Some people use a よ
kana as notation for Yoneda in commutative diagrams. As for functors, when people refer to よ
they usually mean covariant ones - there is yo operator. In Я we also have contravariant version of this operator which is called ya.
So I decided to use Cyrillic letter Я
(pronounced as ya
) which means me
or I
in Slavic languages. I found this coincidence fancy. It doesn’t really belong to any specific nationality or a country, it’s an artefact of the culture I absorbed.
So far we covered flat mappings. However if you want to work with effects - it’s not enough. We need to be able to chain computations, traverse structures and manipulate control flow in every possible way - so we need to have effects in objects already (either on source or target sides).
For that we need Kleisli morphisms - we will talk about it next time.
Continue: Bind and traverse with Kleisli morphisms
In case if you want to go deeper into this topic: