-
Notifications
You must be signed in to change notification settings - Fork 374
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
Interface resolution bug #72
Comments
Comment by edwinb Diamond shaped inheritance structures are awkward because implementations of the same interface aren't guaranteed to be equal. There's a bit of noise in the error message, but it looks like it doesn't know whether to go to Semigroup via Monoid or VerifiedSemigroup. So, this code as it stands isn't going to work without some modification. This diamond issue is a pain and I don't know if anyone has found a nice solution for this sort of problem (with proofs) yet. By the way, I don't think we should use the names |
Comment by nickdrozd I'm pretty sure this is what's responsible for blocking the proof at https://github.com/idris-lang/Idris-dev/pull/4848/files#diff-fb2a7c0a9ce133762a38755823a01d7aR73.
|
Comment by nickdrozd This change does not fix the issue, or even affect the error message: -interface (VerifiedSemigroup a, Monoid a) => VerifiedMonoid a where
+interface (Monoid a, VerifiedSemigroup a) => VerifiedMonoid a where |
Comment by faserprodukt
@edwinb I'm not sure if this fits the problem, but the comment reminds me of the recent Tabled Typeclass Resolution paper. |
Comment by Sventimir
@nickdrozd once suggested in a dicussion on Idris-dev repo, that these interfaces should actually be merged together (i.e. |
Print expected and given output when test fails.
Another alternative would be to index the verified version by the raw one. public export
interface SemigroupV ty (sem : Semigroup ty) where
semigroupOpIsAssociative : (l, c, r : ty) ->
l <+> (c <+> r) = (l <+> c) <+> r However trying to give an implementation for this interface currently More pressing matter: Should we remove |
IMO the value of that code is to illustrate how dependent types can be |
"Some difficulties" being that it's unusable to prove anything There are actual proofs in the library and the fact that they |
I'm not sure what you mean. Lots of things are proved there. It's proved that monoids have unique inverses. Cancellation and unique solution laws are proved for groups. It's proved that group homomorphisms preserve neutrals and inverses. In Idris 1 it was possible to prove that the inverse operation is distributive in commutative groups. Last I checked it wasn't possible in Idris 2, but again, that's an opportunity for improvement. @Sventimir What do you think? |
@gallais is probably right in that the code shouldn't be left in the current state. However, a few solutions have been proposed and I don't think that deleting the module is the best one. In my opinion we should just merge these Verified interfaces into their "unverified" counterparts. This would have the following benefits:
A possible danger may be in that some existing implementations might require extensions to prove that they actually obey these axioms (which may or may not have been proven so far). This might require more work than it seems, but hopefully shouldn't break anything, so it would all be to the good. |
I am not saying it's the best one but it is a first step and it is In the meantime I think it makes sense to remove the code that lulls |
This opinion is actually quite extreme and radical in the programming language landscape. I am not comfortable with following up on this decision in the language's standard library, even under A moderate way forward would be to create a copy somewhere visible, say as a project with the Idris Community organisation until we have a mature proposal for a usable Verified hierarchy. Then it becomes a concrete proposal. |
I apologize if this is a dead issue or discussion has been moved elsewhere, but it seems like you can flatten the diamond issue (at least in the case @nickdrozd points out) by having module Ex
%default total
interface SemigroupV ty where
(<+>) : ty -> ty -> ty
semigroupOpIsAssociative : (l, c, r : ty) -> l <+> (c <+> r) = (l <+> c) <+> r
interface SemigroupV ty => MonoidV ty where
neutral : ty
monoidNeutralIsNeutralL : (l : ty) -> l <+> neutral = l
monoidNeutralIsNeutralR : (r : ty) -> neutral <+> r = r
SemigroupV ty => Semigroup ty where
(<+>) = Ex.(<+>)
MonoidV ty => Monoid ty where
neutral = Ex.neutral
%hide Ex.(<+>)
mtimes : Monoid a => (n : Nat) -> a -> a
mtimes Z x = Prelude.neutral
mtimes (S k) x = x <+> mtimes k x
mtimesTimes : MonoidV a => (x : a) -> (n, m : Nat) ->
mtimes (n + m) x = mtimes n x <+> mtimes m x
mtimesTimes x Z m = sym $ monoidNeutralIsNeutralR $ mtimes m x
mtimesTimes x (S k) m =
rewrite mtimesTimes x k m in
semigroupOpIsAssociative x (mtimes k x) (mtimes m x) This requires a bit more code than the original, and because of (what I believe to be) #2244, I can't exclude the redundant |
What you suggest would lead to ambiguity errors for all types which already implement |
The idea is that types in the stdlib which can be proven to follow the appropriate laws wouldn't have a direct |
Total outsider here, but to the degree that I understand any of this, it seems plausible. |
People are still hitting the same issueT There has been no movement towards fixing it It is IMO unfixable Let's drop it.
Follow-up to the commit by gallais, this removes the contrib libraries which were using `Control.Algebra`.
Issue by nickdrozd
Wednesday May 06, 2020 at 22:33 GMT
Originally opened as edwinb/Idris2-boot#356
Steps to Reproduce
Stick this code at the bottom of Prelude.idr:
Expected Behavior
No problem
Observed Behavior
mtimesTimes
fails with this error:But the proof itself is fine, and it goes through with this change:
mtimes
, with theMonoid
constraint, says, if you implement those syntactic elements, you get to use this syntactic element.mtimesTimes
, with theVerifiedMonoid
constraint, says, if you further prove certain guarantees about the behavior of those syntactic elements, you also get some guarantees about the behavior of this new element. So the "verified" constraint shouldn't be necessary for definingmtimes
, becausemtimes
doesn't make any guarantees about behavior.The inheritance structure looks like this:
This bug is in Idris 1 too.
The text was updated successfully, but these errors were encountered: