Canonical structures #2258
Replies: 3 comments
-
Looks promising! I haven't played with this, but I think @Alizter has. |
Beta Was this translation helpful? Give feedback.
-
BTW, another alternative is to first define the graph structure, and then to define the special name |
Beta Was this translation helpful? Give feedback.
-
Do you have a small reproducible example where making |
Beta Was this translation helpful? Give feedback.
-
Today I was formalizing an equivalence of categories today between two categories
C
andD
. Both of the categories had concretely defined hom-types with their own namesC_Hom
andD_Hom
, similarly to how the category ofGroups
has an associated typeGroupHomomorphism
defined; but one can also speak about them using the typeclass notation,Hom x y
, where the instance is inferred. The theorems to be proved involved a mix of the two notations.I started running into some quite painful errors where unification was unable to solve simple things like
refine (alpha $@ _)
because$@
expects its first argument to be an element of something which is of the formHom x y
by definition, but insteadalpha
was a 2-cell of the "concrete" typeC_Hom2 f g
, and unification was unable to solve for the missingIsGraph
structure such thatC_Hom2 x y
would have been the projection. Now after unification fails, typeclass search is launched, and it tries to instantiate the typeclass instances in a consistent way. But since the categoryD
was defined more recently thanC
, it guessesisgraph_D is01cat_D
etc. for all the typeclass holes, so unification fails again because it infers the wrong category. So, I had to add lots of annotations.I know that canonical structures can be used to solve for the record that a projection 'comes from', so I added:
Lo and behold, this worked like a charm, and suddenly I was able to remove all my annotations. I was pretty thrilled about this.
I originally had some fears that canonical structures and typeclasses would play together in unexpected and complex ways, leading to dynamics that are difficult to debug. I am no longer as worried about this, because canonical structures is part of unification whereas typeclasses is fairly separate from unification.
I hope this hint is helpful for others having unification woes!
Beta Was this translation helpful? Give feedback.
All reactions