---
layout: default
file: "src/Setoid/Categories/NaturalTransformation.lagda.md"
title: "Setoid.Categories.NaturalTransformation module"
date: "2026-06-12"
author: "the agda-algebras development team"
---
### Natural transformations between minimal functors
This is the [Setoid.Categories.NaturalTransformation][] module of the [Agda Universal Algebra Library][].
A *natural transformation* is the third rung of the basic category-theory ladder, after
[`Category`][Setoid.Categories.Category] and [`Functor`][Setoid.Categories.Functor], and it
is the notion category theory was invented to make precise. Where a functor `F : š ā¶ š`
translates one mathematical world into another, a natural transformation compares two such
translations `F, G : š ā¶ š`: it assigns to every object `A` of š a š-morphism
`component A : Fā A ā¶ Gā A`, in a way that is *uniform* in `A`.
Uniformity is the entire content of the definition. The components must not be ad-hoc
choices made object by object; they must commute with every morphism of `š`, which the
`natural`{.AgdaField} field states as the famous *naturality square*: for each
`f : A ā¶ B` in `š`,
```text
component A
Fā A āāāāāāāāāāāāāāāā Gā A
ā ā
Fā f ā ā Gā f
ā ā
Fā B āāāāāāāāāāāāāāāā Gā B
component B
```
both ways around the square are the same š-morphism ā `component B ā Fā f` equals
`Gā f ā component A` ā up to the *target* category's hom-equality `_ā_`. Intuitively:
first translate by `F` and then convert to `G`, or convert first and then translate by
`G`; naturality says it cannot matter. A family of maps with this property is exactly
what a working mathematician means by a construction that "requires no arbitrary
choices."
The library has already met this notion twice, componentwise:
+ A signature morphism `Ļ : šā ā šā` induces the family
`ā¦ Ļ ā§ A : ⨠šā ā© A ⶠ⨠šā ā© A` of [Setoid.Signatures.Functor][], whose naturality
square (`naturality`) commutes by `refl`; `reduct` precomposes this family into an
algebra's structure map.
+ An adjunction carries two natural families, its `unit` and `counit`
([Setoid.Categories.Adjunction][]), each with its naturality square recorded as a
field.
This record packages the pattern once, so that constructions which *consume* a natural
transformation whole ā the [`Monad`][Setoid.Categories.Monad] record of M4-5e is the
inaugural consumer ā can take one argument instead of a component family and a square.
Where a componentwise rendering already is the canonical form (the `Adjunction` fields,
the `ā¦_ā§` family), it stays canonical; this record is the bundled view, not a
replacement. (`Adjunction` derives `unitNT` / `counitNT` views for free.)
As with the rest of the layer (ADR-006), the record is minimal and self-contained ā no
`agda-categories` dependency ā and every law is stated against the target category's
hom-equality field `_ā_`, so categories with pointwise hom-setoids (the algebra
categories [`Alg`][Setoid.Categories.Algebra]) prove naturality pointwise, with no
function extensionality.
<!--
```agda
{-# OPTIONS --cubical-compatible --exact-split --safe #-}
module Setoid.Categories.NaturalTransformation where
open import Agda.Primitive using ( _ā_ ) renaming ( Set to Type )
open import Level using ( Level )
open import Setoid.Categories.Category using ( Category )
open import Setoid.Categories.Functor using ( Functor )
private variable o ā e oā² āā² eā² : Level
```
-->
#### The record
A `NaturalTransformation F G` consists of the component family and its naturality
square. The components live in the target category `š`, and so does the equality in
which the square commutes.
```agda
record NaturalTransformation
{š : Category o ā e} {š : Category oā² āā² eā²}
(F G : Functor š š) : Type (o ā ā ā āā² ā eā²) where
open Category š renaming ( Obj to šā ; Hom to š[_,_] )
open Category š renaming ( Hom to š[_,_] ; _ā_ to _āį“°_ ; _ā_ to _āį“°_ )
open Functor F renaming ( Fā to Fā ; Fā to Fā )
open Functor G renaming ( Fā to Gā ; Fā to Gā )
field
component : (A : šā) ā š[ Fā A , Gā A ]
natural : {A B : šā} (f : š[ A , B ]) ā component B āį“° Fā f āį“° Gā f āį“° component A
```
A small dictionary for readers coming from the classical literature: what is written
`Ī· : F ā¹ G` with components `Ī·_A` and square `Ī·_B ā F f = G f ā Ī·_A` appears here as
`Ī· : NaturalTransformation F G` with `component Ī· A` and `natural Ī· f`. Vertical and
horizontal composition of natural transformations are *not* defined yet; per the
library's two-consumer rule they will be added when a second construction needs them
(the [`Monad`][Setoid.Categories.Monad] laws below need only the components, which is
also why the monad laws there are stated componentwise).