Anna Williams 3 February 2026
Definition of functor composition
\begin{code}
{-# OPTIONS --safe --without-K #-}
open import MLTT.Spartan
open import UF.FunExt
open import Notation.UnderlyingType
open import Categories.Pre
open import Categories.Functor
open import Categories.Notation.Pre
open import Categories.Notation.Functor
module Categories.Functor-Composition where
\end{code}
We now define functor composition in the expected way.
\begin{code}
module _ {A : Precategory đ€ đ„}
{B : Precategory đŠ đŁ}
{C : Precategory đ€' đ„'}
(G' : Functor B C)
(F' : Functor A B) where
open PrecategoryNotation A
open PrecategoryNotation B
open PrecategoryNotation C
open FunctorNotation F' renaming (functor-map to F)
open FunctorNotation G' renaming (functor-map to G)
f-distrib : {a b c : obj A}
(g : hom b c)
(f : hom a b)
â G (F (g ⊠f)) ïŒ G (F g) ⊠G (F f)
f-distrib g f = G (F (g ⊠f)) ïŒâš i â©
G (F g ⊠F f) ïŒâš ii â©
G (F g) ⊠G (F f) â
where
i = ap G (distributivity g f)
ii = distributivity (F g) (F f)
id-eq : (a : obj A) â G (F đđ
) ïŒ đđ
id-eq a = G (F đđ
) ïŒâš ap G (id-preserved a) â©
G đđ
ïŒâš id-preserved (F a) â©
đđ
â
_Fâ_ : Functor A C
_Fâ_ = combined-functor
where
Fâ : obj A â obj C
Fâ a = G (F a)
Fâ : {a b : obj A} â hom a b â hom (Fâ a) (Fâ b)
Fâ f = G (F f)
combined-functor : Functor A C
combined-functor = functor Fâ Fâ id-eq f-distrib
\end{code}
The identity functor is left and right neutral with repspect to the composition
operation.
\begin{code}
module _ {đ€ đ„ đŠ đŁ : Universe}
{A : Precategory đ€ đ„}
{B : Precategory đŠ đŁ}
(fe : Fun-Ext)
(F' : Functor A B) where
open PrecategoryNotation A
open PrecategoryNotation B
open FunctorNotation F' renaming (functor-map to F)
id-left-neutral-Fâ : (id-functor B) Fâ F' ïŒ F'
id-left-neutral-Fâ = test
where
test : (id-functor B Fâ F') ïŒ F'
test = functor F F _ (f-distrib (id-functor B) F') ïŒâš I â©
functor F F id-preserved (f-distrib (id-functor B) F') ïŒâš II â©
F' â
where
I = ap (λ - â functor F F - (f-distrib (id-functor B) F'))
(dfunext fe (λ _ â hom-is-set B _ _))
II = ap (functor F F id-preserved)
(implicit-dfunext fe
(λ _ â implicit-dfunext fe
(λ _ â implicit-dfunext fe
(λ _ â dfunext fe
(λ _ â dfunext fe
(λ _ â hom-is-set B _ _))))))
id-right-neutral-Fâ : F' Fâ id-functor A ïŒ F'
id-right-neutral-Fâ = test
where
idFA = id-functor A
test : (F' Fâ idFA) ïŒ F'
test = functor F F _ (f-distrib F' idFA) ïŒâš I â©
functor F F id-preserved (f-distrib F' idFA) ïŒâš II â©
F' â
where
I = ap (λ - â functor F F - (f-distrib F' idFA))
(dfunext fe (λ _ â hom-is-set B _ _))
II = ap (functor F F id-preserved)
(implicit-dfunext fe
(λ _ â implicit-dfunext fe
(λ _ â implicit-dfunext fe
(λ _ â dfunext fe
(λ _ â dfunext fe
(λ _ â hom-is-set B _ _))))))
\end{code}
The functor composition operation is associative.
\begin{code}
assoc-Fâ : {A : Precategory đ€ đ„}
{B : Precategory đŠ đŁ}
{C : Precategory đ€' đ„'}
{D : Precategory đŠ' đŁ'}
(fe : Fun-Ext)
(F : Functor A B)
(G : Functor B C)
(H : Functor C D)
â H Fâ (G Fâ F) ïŒ (H Fâ G) Fâ F
assoc-Fâ {_} {_} {_} {_} {_} {_} {_} {_} {A} {B} {C} {D} fe F G H
= functor _ _ (id-eq H (G Fâ F)) (f-distrib H (G Fâ F)) ïŒâš I â©
functor _ _ (id-eq (H Fâ G) F) _ ïŒâš II â©
functor _ _ _ _ â
where
I = ap (λ - â functor _ _ - (f-distrib H (G Fâ F)))
(dfunext fe (λ x â hom-is-set D _ _))
II = ap (functor _ _ _)
(implicit-dfunext fe
(λ _ â implicit-dfunext fe
(λ _ â implicit-dfunext fe
(λ _ â dfunext fe
(λ _ â dfunext fe
(λ _ â hom-is-set D _ _))))))
\end{code}