Murat Kasimov

More about me

Я language (β)

/Я language (β)/Articles/Building an intuition over lax Kleisli morphisms/

Functor t is a mapping between source and target categories, a and o are objects of morphisms - contrA-variantly and cO-variantly positioned accordingly. I'm going to provide both Yonedified and canonical forms of mappings so that you can match them:

[Y]oneda c[O]variant functor `yo` : t a `AR____` target ( source ( a ) ( o ) ) ( t o ) __ : source ( a ) ( o ) `AR____` target ( t a ) ( t o )

Examples: we can map Maybe parameter regardless its existense:

> ( Exist `har'st` A : Maybe Latin ) `yo` Upper = ( Exist `har'st` Upper `ha` A : Maybe Letter ) > ( Empty `har` Unit : Maybe Latin ) `yo` Upper = ( Empty `har` Unit : Maybe Letter ) > ( Exist `har'st` A : Maybe Latin ) `yu'st` B = ( Exist `har'st` B : Maybe Latin ) > ( Empty `har` Unit : Maybe Latin ) `yu'st` B = ( Empty `har` Unit : Maybe Latin )

Examples: we can map World parameter regardless its readiness:

> ( output `ha` Glyph `ha` Letter `ha` Upper `har'st` A : World ASCII ) `yu` Unit : World Unit > ( output : ASCII `AR` World ASCII ) `ho'yu` Unit : ASCII `AR` World Unit

Challenge: We can map List/Tree parameter regardless of what?

What we saw above is mapping of so called flat morphisms - it's not an established term, I just came with it as a contrary to lax Kleisli ones. Kleisli are categories that naturally assosiated with monads so that you have a way to compose them.

Okay, forget about monads for now. What if we try to map such a Kleisli-shaped source morphism using a mapping of an ordinary covariant functor? Well, nothing! It's just got mapped as it is:

[Y]oneda c[O]variant functor `yo` : t a `AR____` target ( source ( a ) ( tt o ) ) ( t ( tt o ) ) __ : source ( a ) ( tt o ) `AR____` target ( t a ) ( t ( tt o ) )

But we often don't want to map it "as it is". There is a way for a functor t to absorb functor tt with some natural transformation:

: t ( tt o ) `AR____` t o

By composing a functor t mapping and this family of natural transformations we get a powerful operator. Note the shape of this glyph - it looks like a hook signifying that some sprouted functor tt was integrated into functor t:

[Y]oneda c[O]variant functor (`yo`) Source lax [K]leisli category (`xk`) `yok` : t a `AR____` target ( source ( a ) ( tt o ) ) ( t o ) ___ : source ( a ) ( tt o ) `AR____` target ( t a ) ( t o )

Examples: we can map Maybe parameter considering its existense:

> ( Exist `har'st` A : Maybe Latin ) `yok` Check `ha` Exist = ( Exist `har'st` A : Maybe Latin ) > ( Exist `har'st` A : Maybe Latin ) `yuk` Check `ha` Exist `har'st` B = ( Exist `har'st` B : Maybe Latin ) > ( Empty `har` Unit : Maybe Unit ) `yok` Check `ha` Exist `ha` B = ( Empty `har` Unit : Maybe Latin ) > ( Exist `har'st` A : Maybe Latin ) `yuk` Check `ha` Empty `har` Unit = ( Empty `har` Unit : Maybe Latin )

Examples: we can map World parameter considering its readiness:

> ( output `ha` Glyph `ha` Letter `ha` Upper `har'st` A : World ASCII ) `yok` Await `ha` output > ( output : ASCII `AR` World ASCII ) `ho_'yok` Await `ha` output

Examples: we can map World parameter considering its readiness and existence:

> ( input : World ( Maybe ASCII ) ) `yok` Retry `ha` output

So far we have seen only mapping of source Kleisli morphisms, but can we get those at target category as well? Yes!

[Y]oneda c[O]variant functor (`yo`) Source lax [K]leisli category (`xk`) Target lax K[L]eisli category (`xl`) `yokl` : t a `AR____` target ( source ( a ) ( tt o ) ) ( tt ( t o ) ) ____ : source ( a ) ( tt o ) `AR____` target ( t a ) ( tt ( t o ) )

We do it in similar way - map over functor t and then apply another family of natural transformations for swapping functors t and tt:

: t ( tt o ) `AR____` tt ( t o )

Examples: we can map Maybe parameter regardless its existense:

> Exist `har'st` A `yokl` Check `ha` Await `ha` output `ha` Glyph `ha` Letter `ha` Upper : World ( Maybe ASCII ) > Exist `har'st` Upper `ha` A `yokl` Check `ha` Await `ha` output `ha` Glyph `ha` Letter : World ( Maybe ASCII ) > Exist `har'st` Letter `ha` Upper `ha` A `yokl` Check `ha` Await `ha` output `ha` Glyph : World ( Maybe ASCII ) > Exist `har'st` Glyph `ha` Letter `ha` Upper `ha` A `yokl` Check `ha` Await `ha` output : World ( Maybe ASCII ) > Exist `har'st` output `ha` Glyph `ha` Letter `ha` Upper `ha` A `yokl` Check `ha` Await : World ( Maybe ASCII ) > Exist `har'st` Await `ha` output `ha` Glyph `ha` Letter `ha` Upper `ha` A `yokl` Check : World ( Maybe ASCII )

Bootcamp: if you want to try to use these operators on practice including their compositions, consider solving exercises at bootcamp.