Setoid.Categories.Functor¶
Functors between minimal categories¶
This is the Setoid.Categories.Functor module of the Agda Universal Algebra Library.
A functor is a structure-preserving translation between categories โ the
categorical analog of a homomorphism. Where a homomorphism of algebras carries
elements to elements while preserving the operations, a Functor ๐ ๐ carries the
objects of ๐ to objects of ๐ (the object map Fโ) and the
morphisms of ๐ to morphisms of ๐ (the hom map Fโ), while
preserving the only structure a category has: identities and composition. Those two
preservation conditions are the functor laws identity and
homomorphism, and โ as everywhere in this layer โ they are stated up to
the target category's hom-equality _โ_, so a category whose hom-equality is
pointwise can prove them pointwise, without function extensionality.
Why insist on the laws, rather than taking any pair of maps (Fโ , Fโ)? Because the
laws are what make diagram-chasing arguments transport along F: a commuting diagram
in ๐ is a tower of composites, and homomorphism is exactly the license to push
F through each composite, corner by corner. The third field, F-resp-โ,
plays the same role for equational rewriting that cong plays for setoid functions:
it lets a proof replace a morphism by an equal one underneath Fโ. (In a setting with
unique identity proofs F-resp-โ would be automatic; with hom-setoids it must be
data, just as Func must carry cong.)
The two running examples in this library are good ones to keep in mind:
reductF ฯ(Setoid.Categories.Reduct) translates the world of๐โ-algebras into the world of๐โ-algebras along a signature morphismฯ: the object map forgets (reindexes) operations, the hom map is the identity on the underlying setoid maps.adjoinUnitF(Classical.Categories.AdjoinUnit) translates semigroups into monoids by freely adjoining a unit: the object map genuinely constructs (it enlarges the carrier), and the hom map extends a homomorphism to the new element.
This module also provides the identity functor idF and functor
composition _โF_. They are what make "functor" a closed vocabulary โ
the composite of two translations is a translation โ and they are needed the moment a
construction must name a composite functor, as the Monad
record does when it types its unit Id โน T and multiplication T โ T โน T.
record Functor (๐ : Category o โ e) (๐ : Category oโฒ โโฒ eโฒ) : Type (o โ โ โ e โ oโฒ โ โโฒ โ eโฒ) where open Category ๐ renaming (Obj to ๐โ; Hom to ๐[_,_]; _โ_ to _โแตแตแต_; id to idแตแตแต; _โ_ to _โแตแตแต_) open Category ๐ renaming (Obj to ๐โ; Hom to ๐[_,_]; _โ_ to _โแถแตแต_; id to idแถแตแต; _โ_ to _โแถแตแต_) field Fโ : ๐โ โ ๐โ Fโ : {A B : ๐โ} โ ๐[ A , B ] โ ๐[ Fโ A , Fโ B ] F-resp-โ : {A B : ๐โ} {f g : ๐[ A , B ]} โ f โแตแตแต g โ Fโ f โแถแตแต Fโ g identity : {A : ๐โ} โ Fโ (idแตแตแต {A}) โแถแตแต idแถแตแต homomorphism : {A B E : ๐โ} {f : ๐[ A , B ] } {g : ๐[ B , E ]} โ Fโ (g โแตแตแต f) โแถแตแต Fโ g โแถแตแต Fโ f
The identity functor and composition of functors¶
The identity functor leaves objects and morphisms untouched; its laws are each hom-setoid's reflexivity.
idF : {๐ : Category o โ e} โ Functor ๐ ๐ idF {๐ = ๐} = record { Fโ = id ; Fโ = id ; F-resp-โ = id ; identity = โ-refl ; homomorphism = โ-refl } where open Category ๐ using ( โ-refl )
Functors compose in the application order of their object maps: (G โF F) first
applies F, then G, on objects and morphisms alike. Each composite law unfolds to
"push the inner functor's law through the outer functor, then apply the outer
functor's law" โ one F-resp-โ followed by one โ-trans, a pattern worth noticing
because every composite-functor proof in this library has this shape.
infixr 9 _โF_ _โF_ : {๐ : Category o โ e} {๐ : Category oโฒ โโฒ eโฒ} {๐ : Category oโณ โโณ eโณ} โ Functor ๐ ๐ โ Functor ๐ ๐ โ Functor ๐ ๐ _โF_ {๐ = ๐} G F = record { Fโ = ฮป A โ G.Fโ (F.Fโ A) ; Fโ = ฮป f โ G.Fโ (F.Fโ f) ; F-resp-โ = ฮป fโg โ G.F-resp-โ (F.F-resp-โ fโg) ; identity = โ-trans (G.F-resp-โ F.identity) G.identity ; homomorphism = โ-trans (G.F-resp-โ F.homomorphism) G.homomorphism } where open Category ๐ using ( โ-trans ) module F = Functor F module G = Functor G