Setoid.Categories.Category¶
A minimal category with a hom-setoid¶
This is the Setoid.Categories.Category module of the Agda Universal Algebra Library.
A category is the simplest mathematical setting in which one can speak of objects
and of structure-preserving passages between them, without saying what the objects
are made of. The data is: a collection of objects; for each pair of objects a
collection of morphisms (Hom A B, drawn as arrows A βΆ B); an identity arrow
on every object; and a composition taking g : B βΆ C and f : A βΆ B to
g β f : A βΆ C. The laws β associativity of composition and the two identity laws β
are exactly the monoid axioms, generalized to a setting where two arrows compose only
when their endpoints match. That is the right level of generality for this library's
purposes: the categories we care about have algebras (or signatures, or setoids) as
objects and homomorphisms (or signature morphisms, or setoid functions) as arrows,
and theorems stated at the category level β functoriality, adjointness, monad laws β
then apply to all of them at once. The reader who wants a single mental picture
should hold on to the category of π-algebras: objects are algebras, arrows are
homomorphisms, composition is composition of maps
(Alg).
Category o β e is a self-contained, agda-categories-free category record: objects
in Type o, hom types in Type β, and a per-hom-set equivalence _β_ valued in
Type e.
The one departure from the textbook definition deserves emphasis, because it is
forced by the constructive setting and recurs throughout the layer. Classically one
says two morphisms simply are or are not equal; here every hom-set carries its own
equivalence relation _β_, supplied as a field, and all laws are stated against it.
Carrying _β_ as a field β rather than fixing it to propositional _β‘_ β is what
lets the category of algebras use pointwise homomorphism equality ("the underlying
maps agree on every element"), which _β‘_ cannot express under --safe without
function extensionality. The two instances built so far sit at the two extremes
(ADR-006): the category Sig of signatures uses _β‘_ and proves its laws by refl
(Overture.Signatures.Morphisms), while the category Alg π of algebras uses the
pointwise hom-setoid _β_ (Setoid.Categories.Algebra). One record accommodates
both precisely because the hom-equality is data.
The record is deliberately minimal β exactly the data and laws we need to express
reducts as functors, adjunctions, and monads β and is pure Type-level category
theory (no Setoid import). It lives under Setoid.Categories because its current
consumers are setoid-based. The rest of the vocabulary builds on it in order:
Functor (translations between categories),
NaturalTransformation (comparisons
between translations), Adjunction (free β£
forgetful pairs), and Monad (formal-expression
structure, e.g. terms-with-substitution).
record Category (o β e : Level) : Type (lsuc (o β β β e)) where infixr 9 _β_ infix 4 _β_ field Obj : Type o Hom : Obj β Obj β Type β _β_ : {A B : Obj} β Hom A B β Hom A B β Type e id : {A : Obj} β Hom A A _β_ : {A B C : Obj} β Hom B C β Hom A B β Hom A C β-equiv : {A B : Obj} β IsEquivalence (_β_ {A} {B}) assoc : {A B C D : Obj} {f : Hom A B} {g : Hom B C} {h : Hom C D} β (h β g) β f β h β (g β f) identityΛ‘ : {A B : Obj} {f : Hom A B} β id β f β f identityΚ³ : {A B : Obj} {f : Hom A B} β f β id β f β-resp-β : {A B C : Obj} {f g : Hom B C} {h i : Hom A B} β f β g β h β i β f β h β g β i -- Reflexivity, symmetry, and transitivity of each hom-set's equivalence, -- surfaced for use in functor-law and instance proofs. β-refl : {A B : Obj} {f : Hom A B} β f β f β-refl = IsEquivalence.refl β-equiv β-sym : {A B : Obj} {f g : Hom A B} β f β g β g β f β-sym = IsEquivalence.sym β-equiv β-trans : {A B : Obj} {f g h : Hom A B} β f β g β g β h β f β h β-trans = IsEquivalence.trans β-equiv