Dependent Types and Fibrations

Appendix C

3 min read

Dependent Types and Fibrations

Types that vary with context require machinery that tracks the variation. A query valid against one schema is nonsense against another; a recommendation "best" for one user is irrelevant to the next. This appendix provides the formal vocabulary: dependent types from type theory and fibrations from category theory.

Dependent Types

Dependent Type

A dependent type is a family of types indexed by values of another type. If BB is a type and P:BUP : B \to \mathcal{U} assigns a type P(b)P(b) to each b:Bb : B, then PP is a dependent type over BB. The fiber over bb is the type P(b)P(b).

Π-Type (Dependent Product)

Given BB and P:BUP : B \to \mathcal{U}, the Π-type Πb:BP(b)\Pi_{b : B} P(b) is the type of functions that, given any b:Bb : B, return a value of type P(b)P(b). When PP is constant, this reduces to the ordinary function type BPB \to P.

Σ-Type (Dependent Sum)

The Σ-type Σb:BP(b)\Sigma_{b : B} P(b) is the type of pairs (b,p)(b, p) where b:Bb : B and p:P(b)p : P(b). When PP is constant, this reduces to the ordinary product B×PB \times P.

Π-types correspond to universal quantification (b.P(b)\forall b.\, P(b)); Σ-types to existential quantification (b.P(b)\exists b.\, P(b)) with a witness. This is the propositions-as-types correspondence.

Fibrations

Fibration

A functor p:EBp : \mathcal{E} \to \mathcal{B} is a fibration if it satisfies the lifting property: for every morphism f:BBf : B' \to B in B\mathcal{B} and every object EE in E\mathcal{E} with p(E)=Bp(E) = B, there exists a cartesian lift of ff to E\mathcal{E}. The fiber over BB is the subcategory EB\mathcal{E}_B of objects mapping to BB.

Reindexing

Given a fibration p:EBp : \mathcal{E} \to \mathcal{B} and morphism f:BBf : B' \to B, the reindexing functor f:EBEBf^* : \mathcal{E}_B \to \mathcal{E}_{B'} sends objects in the fiber over BB to objects in the fiber over BB'. This is the functorial version of substitution.

Correspondence

Type TheoryFibration
Type family P:BUP : B \to \mathcal{U}Fibration p:EBp : \mathcal{E} \to \mathcal{B}
Fiber P(b)P(b)Fiber category Eb\mathcal{E}_b
Substitution P[f]P[f]Reindexing ff^*
Π-type Πb:BP(b)\Pi_{b:B} P(b)Right adjoint to reindexing
Σ-type Σb:BP(b)\Sigma_{b:B} P(b)Left adjoint to reindexing

The Third Mode's predicates are fibered: "valid query" depends on schema, "best option" depends on preference context, "permitted action" depends on authorization context. Fibrations make this dependence explicit and reindexing coherent. See A14.

← Back to AppendicesBack to The Proofs →