Towards a specification of theory refinements › Shallow refinements might be all you need? [01HV]

One thing that users might expect to be able to do is form deep refinements like in ML modules, where instead of specialising a field of the top-level structure, you specialise a field of a substructure. For example, suppose we had defined rings in the following way:

theory Ring where
  car: Set
  additive: AbGroup / {car => car}
  multiplicative: Monoid / {car => car}
  dist/left: // ...
  dist/right: // ...

Then we might want to consider a ring structure on the integers in which the addition is given by integer addition, which makes us want to be able to write a theory refinement like Ring / {car => Int, additive.join => Int/add} or something. I would like to posit, if I can, that this is unnecessary.

The issue is that in practice, a composite structure like that of rings ought to be flattened anyway. So we would instead really want something like:

theory Ring where
  car: Set

  include additive: AbGroup / {car => car} renaming
    unit => zero
    join => add
    
  include multiplicative: Monoid / {car => car}
    join => mul
    unit => one

  // ... dist/left, dist/right

Above I have introduced a few new construct: theory inclusion (distinct from inheritance) and theory renaming. What this should unravel to is something like the following:

theory Ring where
  car: Set
  add: car -> car -> car
  zero: car
  // ... add/assoc, add/zero/left, add/zero/right, add/comm
  mul: car -> car -> car
  one: car
  // ... mul/assoc, mul/one/left, mul/one/right,
  // ... dist/left, dist/right
  additive: AbGroup / {join => add, unit => zero, ...}
  multiplicative: Monoid / {join => mul, unit => one, ...}

Because we have named the substructures, the system would not emit any canonical inheritance coercions from Ring to AbGroup or Monoid, as these would not be coherent anyway. The additive and multiplicative components now serve mere “tokens” by which you can access the additive subgroup or the multiplicative monoid all at once, but these are singletons and therefore would not appear in the construction of a given ring.

Coming back to our example, we see that we can obtain the theory of ring structures on integer addition by a shallow refinement Ring / {car => Int, add => Int/add}. I believe that by keeping hierarchies flat in the style of Mathematical Components, we will always be able to obtain the needful refinements shallowly.