module Cat.Functor.Concrete where
Concrete categoriesπ
A category is concrete if it comes equipped with a faithful functor into
module _ {o β} (C : Precategory o β) where
open Cat.Reasoning C
record Concrete (ΞΊ : Level) : Type (o β β β lsuc ΞΊ) where
no-eta-equality
field
: Functor C (Sets ΞΊ)
Forget : is-faithful Forget has-faithful
Constructing concrete categoriesπ
When we construct a category, we typically prove the associativity/unitality conditions βby handβ. However, this can be quite tedious for syntactic presentations of categories, as it involves a large amount of induction. However, these presentations are often meant to present some category of structured functions between sets: if the presentation is injective, then we can derive the category laws by simply lifting the good definitional behaviour of functions along the presentation function.
The following record contains the data required to perform this trick.
record make-concrete
{o β : Level}
(Ob : Type o) (Hom : Ob β Ob β Type β)
: TypeΟ
where
no-eta-equality
field
: β {x} β Hom x x
id _β_ : β {x y z} β Hom y z β Hom x y β Hom x z
{lvl} : Level
: Ob β Type lvl
Fβ : β {x} β is-set (Fβ x)
Fβ-is-set
: β {x y} β Hom x y β Fβ x β Fβ y
Fβ : β {x y} {f g : Hom x y} β (β a β Fβ f a β‘ Fβ g a) β f β‘ g
Fβ-inj : β {x} β (a : Fβ x) β Fβ id a β‘ a
F-id : β {x y z} (f : Hom y z) (g : Hom x y) (a : Fβ x) β Fβ (f β g) a β‘ Fβ f (Fβ g a) F-β
We can show that our putative hom sets are actually sets by lifting the hlevel proof along the injection.
abstract
make-is-set: β x y β is-set (Hom x y)
= injectiveβis-set (Fβ-inj β happly) (fun-is-hlevel 2 Fβ-is-set) make-is-set x y
Likewise, all equations can be lifted as well.
make-idl: β {x y} (f : Hom x y)
β id β f β‘ f
= Fβ-inj Ξ» a β
make-idl f (id β f) a β‘β¨ F-β id f a β©
Fβ (Fβ f a) β‘β¨ F-id (Fβ f a) β©
Fβ id
Fβ f a β
make-idr: β {x y} (f : Hom x y)
β f β id β‘ f
= Fβ-inj Ξ» a β
make-idr f (f β id) a β‘β¨ F-β f id a β©
Fβ (Fβ id a) β‘β¨ ap (Fβ f) (F-id a) β©
Fβ f
Fβ f a β
make-assoc: β {w x y z} (f : Hom y z) (g : Hom x y) (h : Hom w x)
β f β (g β h) β‘ (f β g) β h
= Fβ-inj Ξ» a β
make-assoc f g h (f β (g β h)) a β‘β¨ F-β f (g β h) a β ap (Fβ f) (F-β g h a) β©
Fβ (Fβ g (Fβ h a)) β‘Λβ¨ F-β (f β g) h a β F-β f g (Fβ h a) β©
Fβ f ((f β g) β h) a β Fβ
Used naively, make-concrete
would result in unreadable goals. To avoid this, we provide macros that
expand out the proofs in make-concrete
into a top-level definition
implemented via copattern matching.
define-concrete-category: β {o β} {Ob : Type o} {Hom : Ob β Ob β Type β}
β Name β make-concrete Ob Hom β TC β€
declare-concrete-category: β {o β} {Ob : Type o} {Hom : Ob β Ob β Type β}
β Name β make-concrete Ob Hom β TC β€
The details of the macro are omitted to spare the innocent reader.
make-concrete-category: β {o β} {Ob : Type o} {Hom : Ob β Ob β Type β}
β Bool β Name β make-concrete Ob Hom β TC Name
{o} {β} {Ob} {Hom} declare? nm mk = do
make-concrete-category
`mk β quoteΟTC mk
`O β quoteTC Ob
`H β quoteTC Hom
(Precategory o β)
ty β quoteTC Ξ» where
case declare? of β declare (argN nm) ty
true β pure tt
false
-- Need to use field projections to avoid issues with implicit instantiation.
define-function nm $(proj (quote Precategory.Ob)) ] `O β·
clause [] [ argN (proj (quote Precategory.Hom)) ] `H β·
clause [] [ argN
clause
[](proj (quote Precategory.Hom-set)) ]
[ argN (def (quote make-is-set) [ argN `mk ]) β·
clause(implicits `O ["x"])
(argN (proj (quote Precategory.id)) β· implicit-patterns 1)
(def (quote id) [ argN `mk , argH (var 0 []) ]) β·
clause(implicits `O ["x", "y", "z"])
(argN (proj (quote Precategory._β_)) β· implicit-patterns 3)
(def (quote _β_) [ argN `mk , argH (var 2 []) , argH (var 1 []) , argH (var 0 []) ]) β·
clause(implicits `O ["x", "y"])
(argN (proj (quote Precategory.idr)) β· implicit-patterns 2)
(def (quote make-idr) [ argN `mk , argH (var 1 []) , argH (var 0 []) ]) β·
clause(implicits `O ["x", "y"])
(argN (proj (quote Precategory.idl)) β· implicit-patterns 2)
(def (quote make-idl) [ argN `mk , argH (var 1 []) , argH (var 0 []) ]) β·
clause(implicits `O ["w", "x", "y", "z"])
(argN (proj (quote Precategory.assoc)) β· implicit-patterns 4)
(def (quote make-assoc) [ argN `mk , argH (var 3 []) , argH (var 2 []) , argH (var 1 []) , argH (var 0 []) ]) β·
[]
pure nmwhere
open make-concrete
: Term β List String β Telescope
implicits = map (_, argH ty)
implicits ty
: Nat β List (Arg Pattern)
implicit-patterns 0 = []
implicit-patterns (suc n) = argH (var n) β· implicit-patterns n
implicit-patterns
: Nat β List (Arg Term)
implicit-args 0 = []
implicit-args (suc n) = argH (var n []) β· implicit-args n
implicit-args
= do
declare-concrete-category nm mk
make-concrete-category true nm mk
pure tt
= do
define-concrete-category nm mk
make-concrete-category false nm mk pure tt