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

Support implicit indexes in interfaces #3420

Open
2 tasks done
spcfox opened this issue Nov 20, 2024 · 0 comments
Open
2 tasks done

Support implicit indexes in interfaces #3420

spcfox opened this issue Nov 20, 2024 · 0 comments

Comments

@spcfox
Copy link

spcfox commented Nov 20, 2024

  • I have read CONTRIBUTING.md.
  • I have checked that there is no existing PR/issue about my proposal.

Motivation

I am currently developing a library with proofs in Idris 2. I want to define an interfaces like this:

interface LawfulSemigroup m {auto 0 semigroup : Semigroup m} where
  -- ...

interface LawfulMonoid m {auto 0 monoid : Monoid m} where
  lawfulSemigroup : LawfulSemigroup m
  -- ...

But interfaces doesn't support implicit indexes. I can use constraints like this:

interface Semigroup m => LawfulSemigroup m where
  -- ...

interface Monoid m => LawfulSemigroup m => LawfulMonoid m where
  -- ...

But this is a bad definition, because it does not guarantee that Monoid and LawfulSemigroup use the same Semigroup 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 and LawfulApplicative are indexed by implicit Functor and Applicative.

Conclusion

Implicit interface indexes can be useful, which is why I suggest adding support for them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant