module Cat.Instances.InternalFunctor.Compose where

Functoriality of internal functor compositionπŸ”—

Internal functor composition is functorial, when viewed as an operation on internal functor categories. This mirrors the similar results for composition of ordinary functors.

To show this, we will need to define whiskering and horizontal composition of internal natural transformations.

  _β—‚i_
    : {F G : Internal-functor 𝔹 β„‚}
    β†’ F =>i G β†’ (H : Internal-functor 𝔸 𝔹) β†’ F Fi∘ H =>i G Fi∘ H

  _β–Έi_
    : {F G : Internal-functor 𝔸 𝔹}
    β†’ (H : Internal-functor 𝔹 β„‚) β†’ F =>i G β†’ H Fi∘ F =>i H Fi∘ G

  _β—†i_
    : {F G : Internal-functor 𝔹 β„‚} {H K : Internal-functor 𝔸 𝔹}
    β†’ F =>i G β†’ H =>i K β†’ F Fi∘ H =>i G Fi∘ K
These are almost identical to their 1-categorical counterparts, so we omit their definitions.
  (Ξ± β—‚i H) .Ξ·i x = Ξ± .Ξ·i (H .Fiβ‚€ x)
  (Ξ± β—‚i H) .is-naturali x y f = Ξ± .is-naturali _ _ _
  (Ξ± β—‚i H) .Ξ·i-nat x Οƒ = β„‚.begini
    Ξ± .Ξ·i (H .Fiβ‚€ x) [ Οƒ ] β„‚.≑i⟨ Ξ± .Ξ·i-nat _ Οƒ βŸ©β„‚.≑i
    Ξ± .Ξ·i (H .Fiβ‚€ x ∘ Οƒ)   β„‚.≑i⟨ ap (Ξ± .Ξ·i) (H .Fiβ‚€-nat x Οƒ) βŸ©β„‚.≑i
    Ξ± .Ξ·i (H .Fiβ‚€ (x ∘ Οƒ)) ∎

  (H β–Έi Ξ±) .Ξ·i x = H .Fi₁ (Ξ± .Ξ·i x)
  (H β–Έi Ξ±) .is-naturali x y f =
    sym (H .Fi-∘ _ _) βˆ™ ap (H .Fi₁) (Ξ± .is-naturali _ _ _) βˆ™ H .Fi-∘ _ _
  (H β–Έi Ξ±) .Ξ·i-nat x Οƒ = β„‚.casti $
    H .Fi₁-nat _ Οƒ β„‚.βˆ™i Ξ» i β†’ H .Fi₁ (Ξ± .Ξ·i-nat x Οƒ i)

  _β—†i_ {F} {G} {H} {K} Ξ± Ξ² .Ξ·i x = G .Fi₁ (Ξ² .Ξ·i x) β„‚.∘i Ξ± .Ξ·i (H .Fiβ‚€ x)
  _β—†i_ {F} {G} {H} {K} Ξ± Ξ² .is-naturali x y f =
    (G .Fi₁ (Ξ² .Ξ·i _) β„‚.∘i Ξ± .Ξ·i _) β„‚.∘i F .Fi₁ (H .Fi₁ f)   β‰‘βŸ¨ β„‚.pullri (Ξ± .is-naturali _ _ _) βŸ©β‰‘
    G .Fi₁ (Ξ² .Ξ·i _) β„‚.∘i (G .Fi₁ (H .Fi₁ f) β„‚.∘i Ξ± .Ξ·i _)   β‰‘βŸ¨ β„‚.pullli (sym (G .Fi-∘ _ _) βˆ™ ap (G .Fi₁) (Ξ² .is-naturali _ _ _)) βŸ©β‰‘
    G .Fi₁ (K .Fi₁ f 𝔹.∘i Ξ² .Ξ·i _) β„‚.∘i Ξ± .Ξ·i _              β‰‘βŸ¨ β„‚.pushli (G .Fi-∘ _ _) βŸ©β‰‘
    G .Fi₁ (K .Fi₁ f) β„‚.∘i (G .Fi₁ (Ξ² .Ξ·i _) β„‚.∘i Ξ± .Ξ·i _)   ∎
  _β—†i_ {F} {G} {H} {K} Ξ± Ξ² .Ξ·i-nat x Οƒ = β„‚.begini
    (G .Fi₁ (Ξ² .Ξ·i x) β„‚.∘i Ξ± .Ξ·i (H .Fiβ‚€ x)) [ Οƒ ]       β„‚.≑i⟨ β„‚.∘i-nat _ _ _ βŸ©β„‚.≑i
    G .Fi₁ (Ξ² .Ξ·i x) [ Οƒ ] β„‚.∘i Ξ± .Ξ·i (H .Fiβ‚€ x) [ Οƒ ]   β„‚.≑i⟨ (Ξ» i β†’ G .Fi₁-nat (Ξ² .Ξ·i x) Οƒ i β„‚.∘i Ξ± .Ξ·i-nat (H .Fiβ‚€ x) Οƒ i) βŸ©β„‚.≑i
    G .Fi₁ (Ξ² .Ξ·i x [ Οƒ ]) β„‚.∘i Ξ± .Ξ·i (H .Fiβ‚€ x ∘ Οƒ)     β„‚.≑i⟨ (Ξ» i β†’ G .Fi₁ (Ξ² .Ξ·i-nat x Οƒ i) β„‚.∘i Ξ± .Ξ·i (H .Fiβ‚€-nat x Οƒ i)) βŸ©β„‚.≑i
    G .Fi₁ (Ξ² .Ξ·i (x ∘ Οƒ)) β„‚.∘i Ξ± .Ξ·i (H .Fiβ‚€ (x ∘ Οƒ))   ∎

With that out of the way, we can prove the main result.

  Fi∘-functor
    : Functor (Internal-functors 𝔹 β„‚ Γ—αΆœ Internal-functors 𝔸 𝔹) (Internal-functors 𝔸 β„‚)
  Fi∘-functor .Fβ‚€ (F , G) = F Fi∘ G
Much like whiskering and horizontal composition, this is identical to the result involving functor composition. The only difference is the addition of extra naturality conditions, which are easy to prove.
  Fi∘-functor .F₁ {F , G} {H , K} (Ξ± , Ξ²) = Ξ± β—†i Ξ²
  Fi∘-functor .F-id {F , G} = Internal-nat-path Ξ» x β†’
    F .Fi₁ (𝔹.idi _) β„‚.∘i β„‚.idi _ β‰‘βŸ¨ ap (β„‚._∘i β„‚.idi _) (F .Fi-id) βŸ©β‰‘
    β„‚.idi _ β„‚.∘i β„‚.idi _          β‰‘βŸ¨ β„‚.idli _ βŸ©β‰‘
    β„‚.idi _ ∎
  Fi∘-functor .F-∘ {F , G} {H , J} {K , L} (Ξ± , Ξ²) (Ξ³ , Ο„) = Internal-nat-path Ξ» x β†’
    K .Fi₁ (Ξ² .Ξ·i _ 𝔹.∘i Ο„ .Ξ·i _) β„‚.∘i Ξ± .Ξ·i _ β„‚.∘i Ξ³ .Ξ·i _            β‰‘βŸ¨ β„‚.pushli (K .Fi-∘ _ _) βŸ©β‰‘
    K .Fi₁ (Ξ² .Ξ·i _) β„‚.∘i K .Fi₁ (Ο„ .Ξ·i _) β„‚.∘i Ξ± .Ξ·i _ β„‚.∘i Ξ³ .Ξ·i _   β‰‘βŸ¨ β„‚.extend-inneri (sym (Ξ± .is-naturali _ _ _)) βŸ©β‰‘
    K .Fi₁ (Ξ² .Ξ·i _) β„‚.∘i Ξ± .Ξ·i _ β„‚.∘i H .Fi₁ (Ο„ .Ξ·i _) β„‚.∘i Ξ³ .Ξ·i _   β‰‘βŸ¨ β„‚.associ _ _ _ βŸ©β‰‘
    (K .Fi₁ (Ξ² .Ξ·i x) β„‚.∘i Ξ± .Ξ·i _) β„‚.∘i H .Fi₁ (Ο„ .Ξ·i _) β„‚.∘i Ξ³ .Ξ·i _ ∎