type-theoretic definition of category

Type-theoretic definition of category


Category theory

Type theory

natural deduction metalanguage, practical foundations

  1. type formation rule
  2. term introduction rule
  3. term elimination rule
  4. computation rule

type theory (dependent, intensional, observational type theory, homotopy type theory)

syntax object language

computational trinitarianism =
propositions as types +programs as proofs +relation type theory/category theory

logiccategory theorytype theory
trueterminal object/(-2)-truncated objecth-level 0-type/unit type
falseinitial objectempty type
proposition(-1)-truncated objecth-proposition, mere proposition
proofgeneralized elementprogram
cut rulecomposition of classifying morphisms / pullback of display mapssubstitution
cut elimination for implicationcounit for hom-tensor adjunctionbeta reduction
introduction rule for implicationunit for hom-tensor adjunctioneta conversion
logical conjunctionproductproduct type
disjunctioncoproduct ((-1)-truncation of)sum type (bracket type of)
implicationinternal homfunction type
negationinternal hom into initial objectfunction type into empty type
universal quantificationdependent productdependent product type
existential quantificationdependent sum ((-1)-truncation of)dependent sum type (bracket type of)
equivalencepath space objectidentity type/path type
equivalence classquotientquotient type
inductioncolimitinductive type, W-type, M-type
higher inductionhigher colimithigher inductive type
-0-truncated higher colimitquotient inductive type
coinductionlimitcoinductive type
completely presented setdiscrete object/0-truncated objecth-level 2-type/preset/h-set
setinternal 0-groupoidBishop set/setoid
universeobject classifiertype of types
modalityclosure operator, (idempotent) monadmodal type theory, monad (in computer science)
linear logic(symmetric, closed) monoidal categorylinear type theory/quantum computation
proof netstring diagramquantum circuit
(absence of) contraction rule(absence of) diagonalno-cloning theorem
synthetic mathematicsdomain specific embedded programming language

homotopy levels


Type-theoretic definition of category


There are two main styles of definition of category in the literature: one which immediately generalises to the usual definition of internal category and one which immediately generalises to the usual definition of enriched category. Here we consider the latter definition, and show how it may naturally be expressed in dependent type theory.

Note that in a type theory without identity types, where types are presets (without an inherent equality predicate), it is not manifestly possible to express so-called evil ideas in category theory; thus categories are not necessarily strict. In homotopy type theory, we have identity types, but they are not extensional; thus it is also possible to define non-strict categories there (but there is a subtlety; see below).


In a dependent type theory with dependent record types? we can define a type of categories as follows.

We use a two-dimensional syntax, which is convenient to allow inference of implicit parameters?, and to signify notation. We read the horizontal line as a rule, so for instance the second line means that whenever aa and bb have type Obj\mathrm{Obj}, then we have a type hom(a,b)\hom(a,b) (with equality).

The notation p∶−Pp\coloneq P signifies that pp is a proof of the proposition PP (under propositions as types or propositions as some types, this may be the same as p:Pp\colon P, but many type theories treat propositions as distinct from types).

{ Obj:Type, a,b:Objhom(a,b):Type =, a:Obj1 a:hom(a,a), f:hom(b,c)g:hom(a,b)fg:hom(a,c), g:hom(a,b)left-unit∶−1 bg=g, f:hom(a,b)right-unit∶−f1 a=f, f:hom(c,d)g:hom(b,c)h:hom(a,b)-assoc∶−f(gh)=(fg)h }\begin{aligned} \biggl\{&\mathrm{Obj}\colon\mathrm{Type}, \\ &\frac{a,b\colon\mathrm{Obj}}{\hom(a,b)\colon\mathrm{Type}_=}, \\ &\frac{a\colon\mathrm{Obj}}{1_a\colon\hom(a,a)}, \\ &\frac{f\colon\hom(b,c) \quad g\colon\hom(a,b)}{f\circ g\colon\hom(a,c)}, \\ &\frac{g\colon\hom(a,b)}{\mathrm{left}\text{-}\mathrm{unit}\coloneq 1_b\circ g=g}, \\ &\frac{f\colon\hom(a,b)}{\mathrm{right}\text{-}\mathrm{unit}\coloneq f\circ 1_a=f}, \\ &\frac{f\colon\hom(c,d) \quad g\colon\hom(b,c) \quad h\colon\hom(a,b)}{\circ\text{-}\mathrm{assoc}\coloneq f\circ(g\circ h) = (f\circ g)\circ h} \\ &\!\biggr\} \end{aligned}

Here, Type\mathrm{Type} is a type of types, and Type =\mathrm{Type}_= is a type of types with equality predicates (we may or may not have Type=Type =\mathrm{Type}=\mathrm{Type}_=). Specifically:

  • In extensional type theory (with extensional identity types), we have Type=Type =\mathrm{Type} = \mathrm{Type}_=, and the above definition simply makes no use of the equality predicate on the type of objects. In this case we obtain strict categories, although that is not immediately visible from the definition.

  • In dependent type theory without identity types, basically the only option for Type =\mathrm{Type}_= is the type of setoids. In this case we obtain a notion of non-strict category, since the type of objects has no equality predicate at all.

  • In homotopy type theory, it is natural to take Type =\mathrm{Type}_= to be the type of h-sets: types whose identity/path types behave extensionally. We should also restrict the homotopy level of the type of objects, however, since a true 1-category should have no more than a 1-groupoid of objects; thus Type\mathrm{Type} in the definition above is really the type of h-groupoids instead of the type of all small types. That is, we should take Obj\mathrm{Obj} to be 11-truncated in addition to taking each hom(a,b)\hom(a,b) to be 00-truncated.

    This gives a notion of non-strict category (since there is no equality predicate on a 11-truncated type other than isomorphism). However, it is not quite the right definition of “11-category” in homotopy type theory, because nothing requires that the paths in Obj\mathrm{Obj} are the same as the isomorphisms defined categorically. We need to impose a version of the “completeness” condition on a complete Segal space; in other words, we require that the core of the category be the equivalent as a groupoid to the original type of objects.


The defined type of categories cannot itself be a member of Type\mathrm{Type}, otherwise we run into Girard's paradox. This is related to the size issues for categories.

Anonymous from the Peanut Gallery asks: How do we define small categories type-theoretically? It seems to me that a natural thing to try is to make “small” mean “Obj\mathrm{Obj} is a setoid (ie, element of Type =\mathrm{Type}_=)”, but then the coherence conditions on the type operator of morphisms make my head explode. (Namely, if (A,)(A, \simeq) is a setoid, and aaa \simeq a', then we expect hom(a,b)hom(a,b)\hom(a,b) \triangleq \hom(a',b), but I don’t see how \triangleq should be defined! What should the type of homs be now, and what properties should they satisfy?)

Ulrik: The above does define a type of small categories (given that Type\mathrm{Type} is a type of small types). Adding equality to Obj\mathrm{Obj} (making it a setoid), defines small strict categories. Then, as you mention, we need an equality on Type\mathrm{Type} in order to formulate the coherence condition (the type theory might do this automatically, though). To define large categories we need a larger universe of types (just like the situation in set theory).

Toby: In other words, smallness and strictness are two separate things, although sometimes they go together. If TypeType is the type of small types (and therefore is itself a moderate type but not a small type) and similarly for Type =Type_=, then the definition above gives small categories. If TypeType is the type of moderate types but Type =Type_= remains the type of small types with equality, then the definition above gives locally small moderate categories. If TypeType and Type =Type_= are both types of moderate types, then the definition above gives moderate categories. Independently of this, if you change the type of ObjObj from TypeType to Type =Type_= (and add some coherence conditions), then you get strict categories.

But it seems like there's still something to make your head explode: how do we define strict categories in this framework? (The tricky part is the coherence conditions in my previous parenthetical remark above.) You have the right idea that, if aaa \simeq a', then hom(a,b)hom(a,b)\hom(a,b) \triangleq \hom(a',b), but what you're missing is that \triangleq means isomorphism of setoids. That is, we have a rule

p∶−aaf:hom(a,b)conv a,af:hom(a,b), \frac{p\coloneq a \simeq a' \quad f\colon\hom(a,b)}{\mathrm{conv}_{a,a'}f\colon\hom(a',b)} ,

representing a map of setoids conv a,a:hom(a,b)hom(a,b)\mathrm{conv}_{a,a'}\colon \hom(a,b) \to \hom(a',b). (There is a similar rule on the other side.) Then you also need some coherence laws stating that conv a,a=id hom(a,b)\mathrm{conv}_{a,a} = \id_{\hom(a,b)} and conv a,aconv a,a=conv a,a\mathrm{conv}_{a',a''} \circ \mathrm{conv}_{a,a'} = \mathrm{conv}_{a,a''} (and two laws on the other side). I think that this is all.

The definition that I usually use for a strict category, however, is this: a strict category consists of a set (of type Type =Type_=, what we've been calling ‘setoid’ above) OO, a category (in the weak sense defined here) CC, and an essentially surjective functor ¯\overline{} to CC from the discrete category on OO. We then think of OO as the set of objects, the set of morphisms from aa to bb (for a,b:Oa,b\colon O) is hom C(a¯,b¯)\hom_C(\overline{a},\overline{b}), etc. (Again, strictness is independent of smallness; OO might be a small set, or a large proper class, or whatever.)

Anonymous: Ulrik, Toby: Thank you for the advice! You’re exactly right that what I’ve been groping for is strictness, not smallness. My true motivation is to implement a few constructions on functor categories in type theory. However, the way that the exponential in presheaf categories is usually defined has been pretty puzzling to me: given the category Set I\mathrm{Set}^I, the exponential is defined as FG(X)=Set(I(X,)×F,G)F \Rightarrow G (X) = \mathrm{Set}(I(X, -) \times F, G). It’s exactly the lack of strict structure on objects in the type-theoretic definition that has left me puzzled. I’ll go play with the constructions you’ve suggested and see if I can make it work for me.

However, I do have another question, though this one arises out of curiosity rather than for any practical reason. In impredicative type theories (like the calculus of constructions) you basically give up the powerset axiom in exchange for the ability to index over the universe (i.e., you can define types like α:Type.A(α)\forall \alpha:\mathrm{Type}. A(\alpha)). It seems like you would still need a strictness condition to define constructions on functor categories, even though traditional size issues are cunningly rendered unsayable. Has anyone looked at what happens when you formalize category theory in such type theories (or for that matter, in set theories with a set of all sets, like NF)?

Ulrik: Some quick remarks on your last questions: In impredicative type theory strong sums are inconsistent (by interpreting Girard’s paradox again), so you can’t form a type of meta-categories (you can still have types of types, you just can’t sum over ALL types). As for NF (or NFU), the category of sets is not cartesian closed, which causes a host of problems.

Last revised on January 20, 2019 at 01:33:42. See the history of this page for a list of all contributions to it.