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

Interface resolution bug #4853

Open
nickdrozd opened this issue May 6, 2020 · 0 comments
Open

Interface resolution bug #4853

nickdrozd opened this issue May 6, 2020 · 0 comments

Comments

@nickdrozd
Copy link
Contributor

Steps to Reproduce

mtimes' : Monoid a => (n : Nat) -> a -> a
mtimes' Z x = neutral
mtimes' (S k) x = x <+> mtimes' k x

mtimesTimes : VerifiedMonoid 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)

(with appropriate imports)

Expected Behavior

no problem

Observed Behavior

     When checking right hand side of mtimesTimes with expected type
             mtimes' (S k + m) x = mtimes' (S k) x <+> mtimes' m x

     When checking an application of function rewrite__impl:
             Type mismatch between
                     x <+> (mtimes' k x <+> mtimes' m x) =
                     x <+> mtimes' k x <+>
                     mtimes' m x (Type of semigroupOpIsAssociative x
                                                                   (mtimes' k x)
                                                                   (mtimes' m x))
             and
                     (\replaced =>
                        x <+> replaced =
                        x <+> mtimes' k x <+> mtimes' m x) (mtimes' k x <+>
                                                            mtimes' m
                                                                    x) (Expected type)

             Specifically:
                     Type mismatch between
                             (<+>) {{constructor of Control.Algebra.VerifiedSemigroup#Semigroup a {{constructor of Control.Algebra.VerifiedMonoid#VerifiedSemigroup a}}}}
                                   x
                                   (mtimes' k x) <+>
                             mtimes' m x
                     and
                             (<+>) {{constructor of Prelude.Algebra.Monoid#Semigroup ty {{constructor of Control.Algebra.VerifiedMonoid#Monoid a}}}}
                                   x
                                   (mtimes' k x) <+>
                             mtimes' m x

It looks like the typechecker can't figure out that multiple distinct paths down the inheritance hierarchy end up at the same place.

Fixed with this change, which shouldn't be necessary:

-mtimes' : Monoid a => (n : Nat) -> a -> a
+mtimes' : VerifiedMonoid a => (n : Nat) -> a -> a

Also a bug in Idris 2; see https://github.com/edwinb/Idris2/issues/356

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

No branches or pull requests

1 participant