You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 0semigroup: Semigroup m} where
-- ...
interface LawfulMonoid m {auto 0monoid: 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.
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: