-
Notifications
You must be signed in to change notification settings - Fork 380
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
Support implicit indexes in interfaces #3420
Comments
I just noticed this and how it's similar to something I'm already working on, quick question: Why do you want to use the |
Oh, I started working on adding this feature a few days ago
I think using interfaces for this seems natural. I see the following advantages:
|
For point number 1, what you're looking for is copattern syntax https://agda.readthedocs.io/en/latest/language/copatterns.html I'm not quite sure I'm entirely sold on the design of the feature but if you can make it work that would be interesting |
Copatterns looks interesting. Right now I have a working version with implicit parameters in the interfaces. I'll tidy it up and create a PR for discussions |
As far as I understand, there are no copatterns in Idris2 right now? |
that's right, we still need to implement copatterns |
Motivation
I am currently developing a library with proofs in Idris 2. I want to define an interfaces like this:
But interfaces doesn't support implicit indexes. I can use constraints like this:
But this is a bad definition, because it does not guarantee that
Monoid
andLawfulSemigroup
use the sameSemigroup
instance. Such a definition is impossible to use in practice.At the same time, it makes sense to make these indexes
auto
, because in most cases you can deduce from the context for which monoid the proof is required.The proposal
Add support for implicit indexes to interfaces. When desugaring, they are translated to the same record indexes that already support them.
Alternatives considered
You can use records explicitly, but the syntax for interfaces is more convenient. In addition, the interfaces allow for minimal complete implementation. This can be useful for the above example, since it is possible to provide the user with several equivalent sets of laws and allow to prove the most convenient one.
You can make the indexes explicit. But this is inconvenient because we usually don't have named interface instances.
In Lean 4, classes for
LawfulFunctor
andLawfulApplicative
are indexed by implicitFunctor
andApplicative
.Conclusion
Implicit interface indexes can be useful, which is why I suggest adding support for them.
The text was updated successfully, but these errors were encountered: