open import Cat.Instances.Functor open import Cat.Instances.Product open import Cat.Prelude import Cat.Functor.Reasoning as Fr import Cat.Reasoning open Functor open _=>_ module Cat.Instances.Functor.Compose where
Functoriality of functor compositionπ
When the operation of functor composition, , is seen as happening not only to functors but to whole functor categories, then it is itself functorial. This is a bit mind-bending at first, but this module will construct the functor composition functors. Thereβs actually a family of three related functors weβre interested in:
- The functor composition functor itself, having type ;
- The precomposition functor associated with any , which will be denoted in TeX and _! in Agda;
- The postcomposition functor associated with any , which will be denoted ; In the code, thatβs _^*.
Note that the precomposition functor is necessarily βcontravariantβ when compared with , in that it points in the opposite direction to .
Fβ-functor : Functor (Cat[ B , C ] ΓαΆ Cat[ A , B ]) Cat[ A , C ] Fβ-functor {C = C} = go module Fβ-f where private module C = Cat.Reasoning C go : Functor _ _ go .Fβ (F , G) = F Fβ G go .Fβ {y = y , _} (n1 , n2) .Ξ· x = y .Fβ (n2 .Ξ· _) C.β n1 .Ξ· _ go .Fβ {x = F , G} {y = W , X} (n1 , n2) .is-natural _ _ f = (W .Fβ (n2 .Ξ· _) C.β n1 .Ξ· _) C.β F .Fβ (G .Fβ f) β‘β¨ C.pullr (n1 .is-natural _ _ _) β©β‘ W .Fβ (n2 .Ξ· _) C.β W .Fβ (G .Fβ f) C.β n1 .Ξ· _ β‘β¨ C.extendl (W.weave (n2 .is-natural _ _ _)) β©β‘ W .Fβ (X .Fβ f) C.β W .Fβ (n2 .Ξ· _) C.β n1 .Ξ· _ β where module W = Fr W go .F-id {x} = Nat-path Ξ» _ β C.idr _ β x .fst .F-id go .F-β {x} {y , _} {z , _} (f , _) (g , _) = Nat-path Ξ» _ β z .Fβ _ C.β f .Ξ· _ C.β g .Ξ· _ β‘β¨ C.pushl (z .F-β _ _) β©β‘ z .Fβ _ C.β z .Fβ _ C.β f .Ξ· _ C.β g .Ξ· _ β‘β¨ C.extend-inner (sym (f .is-natural _ _ _)) β©β‘ z .Fβ _ C.β f .Ξ· _ C.β y .Fβ _ C.β g .Ξ· _ β‘β¨ C.pulll refl β©β‘ (z .Fβ _ C.β f .Ξ· _) C.β (y .Fβ _ C.β g .Ξ· _) β {-# DISPLAY Fβ-f.go = Fβ-functor #-}
Before setting up the pre/post-composition functors, we define their action on morphisms (natural transformations) first, called whiskerings, first. The mnemonic for triangles is that the base points towards the side that does not change, so in (e.g.) , the is unchanging: this expression has type , as long as .
_β_ : F => G β (H : Functor C D) β F Fβ H => G Fβ H _β_ nt H .Ξ· x = nt .Ξ· _ _β_ nt H .is-natural x y f = nt .is-natural _ _ _ _βΈ_ : (H : Functor E C) β F => G β H Fβ F => H Fβ G _βΈ_ H nt .Ξ· x = H .Fβ (nt .Ξ· x) _βΈ_ H nt .is-natural x y f = sym (H .F-β _ _) β ap (H .Fβ) (nt .is-natural _ _ _) β H .F-β _ _
With the whiskerings already defined, defining and is easy:
module _ (p : Functor C Cβ²) where _! : Functor Cat[ Cβ² , D ] Cat[ C , D ] _! .Fβ G = G Fβ p _! .Fβ ΞΈ = ΞΈ β p _! .F-id = Nat-path Ξ» _ β refl _! .F-β f g = Nat-path Ξ» _ β refl _^* : Functor Cat[ D , C ] Cat[ D , Cβ² ] _^* .Fβ G = p Fβ G _^* .Fβ ΞΈ = p βΈ ΞΈ _^* .F-id = Nat-path Ξ» _ β p .F-id _^* .F-β f g = Nat-path Ξ» _ β p .F-β _ _