Fuss-free universe hierarchies › A new idea: Working your way down from the top › Some dream code [01I1]

What I would like is the best of both worlds: to be allowed to develop the theory with fully unconstrained sizes, and then specialise the theory to more specific sizes later. Consider the following dream code for the theory of categories:

theory Category where
  ob: Type
  hom: ob -> ob -> Type
  // operations and axioms...

There is no implicit polymorphism happening in this definition. It is literally a very large theory of large categories. We can develop the theory of functors and natural transformations at this level too:

theory Functor where
  C: Category
  D: Category
  ob: C.ob -> D.ob
  hom: (x y: C.ob) -> C.hom x y -> D.hom (ob x) (ob y)
  // axioms...

theory NaturalTransformation where
  C: Category
  D: Category
  F: Functor / {C => C, D => D}
  G: Functor / {C => C, D => D}

  go: (x: C.ob) -> D.hom (F.ob x) (G.ob x)
  // naturality axiom...

If we want to talk about small or locally small strict categories, this is going to be very easy, and we can reuse everything from the theory of functors and natural transformations by instantiation.

theory LocallySmallCategory where
  V: Universe
  ob: Type
  hom: ob -> ob -> V

  inherit Category / {ob => ob, hom => hom}

theory SmallCategory where
  U: Universe
  ob: U
  inherit LocallySmallCategory / {V => U, ob => ob}

The above registers implicit coercions SmallCategory >-> LocallySmallCategory >-> Category. So if we want to talk about functors between X: SmallCategory and Y: LocallySmallCategory, we can do so by specialisation with no fuss:

Functor / {C => X, D => Y}

We will also be able to define the large category of small categories, again with no fuss.

theory SmallStrictCategory where
  inherit SmallCategory

  code: U
  code/is-set: is-set code

  encode: code -> ob
  encode/surjective: is-surjective encode

theory CategoryOfSmallStrictCategories where
  U: Universe

  scat: Category
  scat.ob => SmallStrictCategory / {U => U}
  scat.hom X Y => Functor / {C => X, D => Y}
  // ...