module Cat.Functor.Concrete whereConcrete 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
Forget : Functor C (Sets ΞΊ)
has-faithful : is-faithful ForgetConstructing 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
id : β {x} β Hom x x
_β_ : β {x y z} β Hom y z β Hom x y β Hom x z
{lvl} : Level
Fβ : Ob β Type lvl
Fβ-is-set : β {x} β is-set (Fβ x)
Fβ : β {x y} β Hom x y β Fβ x β Fβ y
Fβ-inj : β {x y} {f g : Hom x y} β (β a β Fβ f a β‘ Fβ g a) β f β‘ g
F-id : β {x} β (a : Fβ x) β Fβ id a β‘ a
F-β : β {x y z} (f : Hom y z) (g : Hom x y) (a : Fβ x) β Fβ (f β g) a β‘ Fβ f (Fβ g a)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)
make-is-set x y = injectiveβis-set (Fβ-inj β happly) (fun-is-hlevel 2 Fβ-is-set)Likewise, all equations can be lifted as well.
make-idl
: β {x y} (f : Hom x y)
β id β f β‘ f
make-idl f = Fβ-inj Ξ» a β
Fβ (id β f) a β‘β¨ F-β id f a β©
Fβ id (Fβ f a) β‘β¨ F-id (Fβ f a) β©
Fβ f a β
make-idr
: β {x y} (f : Hom x y)
β f β id β‘ f
make-idr f = Fβ-inj Ξ» a β
Fβ (f β id) a β‘β¨ F-β f id a β©
Fβ f (Fβ id a) β‘β¨ ap (Fβ f) (F-id a) β©
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
make-assoc f g h = Fβ-inj Ξ» a β
Fβ (f β (g β h)) a β‘β¨ F-β f (g β h) a β ap (Fβ f) (F-β g h a) β©
Fβ f (Fβ g (Fβ h a)) β‘Λβ¨ F-β (f β g) h a β F-β f g (Fβ h a) β©
Fβ ((f β g) β h) a β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
make-concrete-category {o} {β} {Ob} {Hom} declare? nm mk = do
`mk β quoteΟTC mk
`O β quoteTC Ob
`H β quoteTC Hom
ty β quoteTC (Precategory o β)
case declare? of Ξ» where
true β declare (argN nm) ty
false β pure tt
-- Need to use field projections to avoid issues with implicit instantiation.
define-function nm $
clause [] [ argN (proj (quote Precategory.Ob)) ] `O β·
clause [] [ argN (proj (quote Precategory.Hom)) ] `H β·
clause
[]
[ argN (proj (quote Precategory.Hom-set)) ]
(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 nm
where
open make-concrete
implicits : Term β List String β Telescope
implicits ty = map (_, argH ty)
implicit-patterns : Nat β List (Arg Pattern)
implicit-patterns 0 = []
implicit-patterns (suc n) = argH (var n) β· implicit-patterns n
implicit-args : Nat β List (Arg Term)
implicit-args 0 = []
implicit-args (suc n) = argH (var n []) β· implicit-args n
declare-concrete-category nm mk = do
make-concrete-category true nm mk
pure tt
define-concrete-category nm mk = do
make-concrete-category false nm mk
pure tt