-
Notifications
You must be signed in to change notification settings - Fork 641
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
Mysterious type mismatch between @@constructors. Interfaces striking back again? #3078
Comments
Hi Nicola, hi all, it seems Idris doubts that the two This doesn't fit with the general idea of interfaces as given in the tutorial, where one reads:
On the other hand, looking at the types, e.g.
one finds that the I'd wish someone could come up with a more in depth introduction to how interfaces work,
Btw, when adding an explicit
the error message becomes really funny (showimplicits switched on):
Ciao, |
This is the same as #2497 - if you have x : Num t and y : Num t, you can't deduce that x = y because of the presence of named implementations. Also, even if we didn't have named instances, you still couldn't deduce x = y because it would still be possible to construct a different instance via the core language. What the tutorial should say is that non-named implementations cannot overlap. Essentially, interfaces are records with a handy syntax for the very common case of overloading names. If you need a lot of control, perhaps you should be using records instead. |
Edwin, I would expect problems with diamond shaped hierarchies or multiple inheritance to possibly trigger "can't disambiguate" errors, not "type mismatch" errors. It also seems to me that such errors should be avoidable by enforcing more strict visibility rules. Here (as in #2497), however, we seem to be facing a more elementary problem: the program
fails now to type check (with 0.11-git:7e7d0eb) with
which seems an Idris bug to me. Ciao, Nicola |
Could some of the problems with diamond shaped hierarchies be alleviated by requiring declarations like
whenever |
This turns out to be a problem with error messages. I'm on a bit of a mission to improve error messages at the minute too... The real error in the code snippet above can be minimised to this definition:
The problem is that it doesn't know whether you mean Vect.Nil or List.Nil, and this causes a chain of other things not being resolved. I'll see if I can find a way to get it to report that instead, since it is the real error... |
The problem is that, if one disambiguates all
, one ends up with
! The problem does not disappear if one defines
|
Most likely the numeric types are different. I wonder if the defaulting I might turn that mechanism off, it probably causes more harm than good, On 20/04/2016 11:36, nicolabotta wrote:
|
You are probably right Edwin! Setting showimplicits reveals that the given equality is homogeneous but the expected one is heterogeneous, for what I understand. Best, Nicola |
To be honest, I think that diamond shaped hierarchies would nice to have solved. I am experiencing some issues with this as well especially when one tries to have things like |
You can avoid the diamond problem like this:
with one issue: Applicative would need to track equalities over dictionaries as well. It would be nice to have a way to specify which superclass instances were used (some kind of sharing constraint) so that we can get the necessary equalities. |
@david-christiansen Thanks for the workaround! |
Is there any chance to get diamond shaped hierarchies working properly as a milestone for 1.0? I would not mind having to write
instead of simply
in situations in which
This would anyway be cleaner and more consistent with the way module features are currently treated: as a default, one cannot access features of modules that have been imported by imported modules, can one? But without support for diamond shaped hierarchies, I really do not see how interfaces |
The code
Fails to type check with
But replacing
with
and
with
makes the code type check fine! Perhaps an error in the implementation of interfaces?
The text was updated successfully, but these errors were encountered: