Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using new syntax for projection instance declarations #2263

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

patrick-nicodemus
Copy link
Contributor

@patrick-nicodemus patrick-nicodemus commented Mar 21, 2025

This commit replaces all Existing Instance proj1 occurrences in the library with the new :: syntax.

I have opted not to replace the occurrences of Coercion as I didn't realize the :> makes it reversible.

@@ -92,11 +92,8 @@ Class Transitive {A} (R : Relation A) :=

(** A [PreOrder] is both Reflexive and Transitive. *)
Class PreOrder {A} (R : Relation A) :=
{ PreOrder_Reflexive : Reflexive R | 2 ;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is funny. Back when the syntax was :> for an existing instance in a Class we had these priorities. When they were removed the parser still accepted and ignored them. Now that we are adding them back in, the priority is back to the original one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was pleasantly surprised that this notation was accepted by the parser.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that mean that this change is also a semantic one? Why should we set the cost of this instance to something other than the default? (And since this wasn't just a rote change, it should have been highlighted in the PR.)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original intention is for the reflexivity instance coming from here to be lower priority than the rest. This was broken some time when we removed the legacy :> syntax.

We have two choices: Either we remove the | 2s or we keep them the way they are. The secondary option seems better as I think I see the reason for choosing a lower priority. During typeclass search, you don't want to try the reflexivity proof from the preorder class of R rather than just choosing a direct reflexivity proof if one is available.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that the original hint had a custom priority of 2. If there was no custom priority in the original hint than this is a mistake and I'll look at it again to see what happened. Maybe I mixed it up with another hint

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As Ali explained, I think historically it had a custom priority of 2, but when the old :> notation for an instance was replaced with an explicit Existing Instance line, that priority was lost (but the | 2 was still in the record field, doing nothing). Then your change caused the priority to go back to 2. Ali suggests that this is probably a good thing, so there is no need to change this PR. I was just pointing out that this is a semantic change, which should have been mentioned, but of course it was the kind of thing that would be easy to miss.

Copy link
Collaborator

@Alizter Alizter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had an initial look and it mostly looks good. Thanks for taking this on. I will do a more thorough review once my previous comments have been addressed.

Copy link
Collaborator

@jdchristensen jdchristensen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this. It looks good to me.

Can you also update Section 3.7 of STYLE.md? It should say that we prefer "::" to "Existing Instance" and that we do not want to use ":>" for coercions, in part because it makes them reversible, and in part because we like being explicit about Coercions. It also has out-of-date info about what ":>" means.

(And another task would be to replace the current uses of ":>" with an explicit Coercion command. They were done without realizing that it made the coercions reversible.)

@jdchristensen
Copy link
Collaborator

This looks good to me, modulo one tweak to STYLE.md.

(And, just to be clear, my comment about removing :> was meant as a task for another PR.)

comment on record projections and typeclasses

Co-authored-by: Dan Christensen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants