---
layout: default
file: "src/Setoid/Categories/Functor.lagda.md"
title: "Setoid.Categories.Functor module"
date: "2026-06-08"
author: "the agda-algebras development team"
---
### 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โ`{.AgdaField}) and the
*morphisms* of `๐` to morphisms of `๐` (the hom map `Fโ`{.AgdaField}), while
preserving the only structure a category has: identities and composition. Those two
preservation conditions are the functor laws `identity`{.AgdaField} and
`homomorphism`{.AgdaField}, 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-โ`{.AgdaField},
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`{.AgdaFunction} and functor
composition `_โF_`{.AgdaFunction}. 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`][Setoid.Categories.Monad]
record does when it types its unit `Id โน T` and multiplication `T โ T โน T`.
<!--
```agda
{-# OPTIONS --cubical-compatible --exact-split --safe #-}
module Setoid.Categories.Functor where
open import Agda.Primitive using ( _โ_ ) renaming ( Set to Type )
open import Function using ( id )
open import Level using ( Level )
open import Setoid.Categories.Category using ( Category )
private variable
o โ e oโฒ โโฒ eโฒ oโณ โโณ eโณ : Level
```
-->
```agda
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.
```agda
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.
```agda
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
```