module Cat.Instances.Sets.CartesianClosed {β„“} where

Sets is (locally) cartesian closedπŸ”—

We show that the category of Sets is locally cartesian closed, i.e. that every map of Sets induces a functor which is right adjoint to the pullback functor

⚠️⚠️⚠️

module _ {A B : Set β„“} (func : ∣ A ∣ β†’ ∣ B ∣) where
  Sets-Ξ  : Functor (Slice (Sets β„“) A) (Slice (Sets β„“) B)
  Sets-Ξ  .Fβ‚€ ob .domain =
    el! (Ξ£[ y ∈ B ] ((f : fibre func y) β†’ fibre (ob .map) (f .fst)))

  Sets-Ξ  .Fβ‚€ ob .map g = g .fst

  Sets-Ξ  .F₁ hom .map (i , fibs) = i , go where
    go : βˆ€ _ β†’ _
    go (x , fx=i) = hom .map (fibs (x , fx=i) .fst) ,
      happly (hom .commutes) _ βˆ™ (fibs (x , fx=i) .snd)
  Sets-Ξ  .F₁ hom .commutes = refl
Sets-lcc : Locally-cartesian-closed (Sets β„“)
Sets-lcc = dependent-product→lcc (Sets ℓ) Sets-finitely-complete Sets-Π adj where
  adj : βˆ€ {a b : Set β„“} (f : ∣ a ∣ β†’ ∣ b ∣) β†’ Base-change _ {X = b} {Y = a} f ⊣ Sets-Ξ  f
  adj f .unit .Ξ· x .map y = x .map y , Ξ» f β†’ (_ , _ , sym (f .snd)) , refl
  adj f .counit .Ξ· x .map ((a , g) , b , p) = g (b , sym p) .fst
  adj f .unit .Ξ· x .commutes = refl
  adj {a} {b} f .unit .is-natural x y g =
    /-Hom-path (funext Ξ» x β†’ Ξ£-pathp (happly (g .commutes) _)
      (funext-dep (Ξ» p β†’ Ξ£-pathp (Ξ£-pathp refl (Ξ£-pathp (Ξ» i β†’ p i .fst)
        (is-set→squarep (λ i j → b .is-tr) _ _ _ _)))
        (is-set→squarep (λ i j → a .is-tr) _ _ _ _))))
  adj f .counit .Ξ· x .commutes = funext Ξ» where
    ((a , g) , b , p) β†’ g (b , sym p) .snd
  adj {a} {b} f .counit .is-natural x y g =
    /-Hom-path (funext Ξ» x β†’ ap (g .map βŠ™ fst βŠ™ x .fst .snd)
      (Ξ£-pathp refl (b .is-tr _ _ _ _)))
  adj {a} {b} f .zig {A} =
    /-Hom-path (funext Ξ» x β†’ Ξ£-pathp refl (Ξ£-pathp refl (b .is-tr _ _ _ _)))
  adj {a} {b} f .zag =
    /-Hom-path (funext (Ξ» x β†’ Ξ£-pathp refl
      (funext Ξ» x β†’ Ξ£-pathp refl (a .is-tr _ _ _ _))))