As we have presented it, dependent type theory has two kinds of entity: types and their elements. In many cases, it is useful to have a type whose elements are themselves types!
- Even though we have not been shy about writing phrases like “Let A be a type”, we do not currently have the ability to say something like “Let f be a polymorphic function on lists”. If we had a type of types like \mathsf {type}~\mathit {type}, we would give f a precise typing like f:{\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod }
}_{(A:\mathsf {type})}}\;\mathsf {List}~A\to \mathsf {List}~A.
- If we had a type of types, we would be able to define more examples of dependent types that do something different depending on some value. For example, we would be able to define a type-level
if expression without relying on large elimination. In fact, we will see that either large elimination or a universe is required to prove that \mathsf {true} is not equal to \mathsf {false}!
We do need to be careful, for two reasons:
- Syntactic objection. A type of types doesn’t make sense, because types are syntactically different kinds of entities from elements. We will solve this by distinguishing between the “code” of a type, which is an element, and the type that it encodes.
- Semantic objection. Even if we address the syntactic objection, a type of all types leads to contradiction via the Burali-Forti/Russell “paradox”, because such a type would include itself. Sidenote: the term “paradox” comes from a time when people were far more confused than we are today; we should think of these as no-go theorems instead. We will solve this by considering only types of some types.
Although there are many ways to handle these things in a technical sense, we will adopt a particular approach described by Rijke. The idea is to have a type \mathcal {U}~\mathit {type} together with a family X:\mathcal {U}\vdash \mathcal {T}[X]~\mathit {type}; then an element X:\mathcal {U} is thought of as encoding the type \mathcal {T}[X]~\mathit {type}.
It can be difficult to understand what is going on in the axiom of universes. It is simplest to understand in the case of n=1, so that we are looking at a single family x:A\vdash B[x]~\mathit {type}. In this case, the universe \mathcal {U}_{A,B} contains each type B[u] for u:A; so the role of the family here is to close the universe under all the components of a family at once. Multiple families are allowed for further expressivity; to see why this is needed, consider the following example of a universe hierarchy:
Many presentations of type theory (including those used in Agda, Rocq, and Lean) impose universe hierarchies at the start. We’ll take an agnostic approach, and just assume a universe where it is needed. We won’t assume that this universe necessarily comes from the hierarchy described above.