Skip to content

[design] new syntax for declaring fields as existing instances #16224

Closed
@Alizter

Description

@Alizter

Today we can do :> to declare an existing instance in a class. This is confusing for newcomers and makes handling record/class syntax more complicated. Therefore it was deprecated in #15802. The alternative there is to using Existing Instance. Whilst this is fine from a semantic standpoint, it would be nice to introduce some syntactic sugar for doing this at the field level. Another thing is that we don't only have to support classes, but records also.

Here is a proposal:

Record Foo := {
  my_data : My_type ;
  my_instance :: My_class ;
}.

This would do the equivalent of:

Record Foo := {
  my_data : My_type ;
  my_instance : My_class ;
}.
Existing Instance my_instance.

Furthermore we could add an attribute to this field, similarly how the :> in a field can have coercion attributes.

Record Foo := {
  my_data : My_type ;
  #[priority = 20]
  my_instance :: My_class ;
}.

Which would do:

Record Foo := {
  my_data : My_type ;
  my_instance : My_class ;
}.
Existing Instance my_instance | 20.

Other attributes could also be added that govern the mode of the input class (if it is happening inside a class) etc.

The :: syntax is a nod to Haskell which inspired the typeclass mechanism in Coq. I think our parser should be able to support it, though I haven't tried. Other alternative's include :$ where $ can be replaced by any ASCII char we settle on.

I believe that we should provide some syntactic sugar before fully removing :> to mean existing instance today.

cc @RalfJung @Blaisorblade @SkySkimmer @proux01

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind: design discussionDiscussion about the design of a feature.part: vernacHigh level command interpretation.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions