-
Notifications
You must be signed in to change notification settings - Fork 660
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
number not accepted as comparable #1281
Comments
Here's an example not involving g : comparable -> ()
g _ = ()
f : number -> ()
f = g Should be accepted, but isn't. |
In some sense this error is dual to that reported in #1270. Maybe the "super/sub relationship" between We have that every
Now what the issue here shows is that 1. is violated by the compiler, while the issue #1270 shows that 2. is violated by the compiler. So maybe somewhere in the compiler instead of "every |
A good theory, but this code seems correct. Unless there's some weird contravariance going on? |
Wait, what about here? If I read it right, the result of |
Do we know that that is the relevant code to look at? I don't know the structure of the compiler/type-checker well enough to judge. My question probably is: Is that code the code that runs when one has inferred a type for some function definition and is now checking whether the type annotation the programmer gave for that function definition is a specialization of the inferred type? Note that this is really about specialization, not about unification. The types |
I'm also not too familiar with the compiler's structure, but search for "comparable" and there are only three source files that turn up. So I can be pretty confident that this function, for example, is why you can't write I can try compiling from source with a change and see if it works. |
It turns out that removing that guard does cause the original program to type check. But, what I didn't see in previous comments is that Having looked over the file for some time, my next question is, what's the difference between a flexible and a rigid type variable? After some googling I couldn't find a satisfactory answer. |
This seems like the right direction. A "rigid" variable is one that is given by the programmer in a type annotation. If someone says "the type is A "flexible" variable is one that is created by the compiler. So the compiler may know that something has type |
Thanks Evan, that's very helpful! So in the example in the second post, both I'm not entirely confident in this though, because I'm not sure how As much as I enjoy diving into this and would appreciate any other information Evan could offer, it's probably best just to wait for him to fix it. |
When you use a value, it is "generalized" so you end up with all flexible variables. Rigid variables should only show up when you are checking type annotations, not at other times. Ultimately, I'd need to dig into this directly to give any further insight, but at this point, I think it has been really narrowed down, so that should be pretty easy when I get a chance! |
Thanks, glad I could help and learn something about type checking at the same time. |
Here is an example of this bug "in the wild". |
Centralizing into #1373, will track from there. |
Here is an example that seems related, maybe is an instance of this bug, but appears to be new with Elm 0.18: f : number -> number -> Bool
f x y = x < y Should be accepted by the compiler, but is not (http://elm-lang.org/try in 0.18 version). According to a thread on the mailing list, https://groups.google.com/d/msg/elm-discuss/om6l_lvCr_4/uiA7zFcvBQAJ, by someone who encountered this in real code, the 0.17 version of the compiler handled this correctly. |
The new combineRigidSupers function makes sure that the rigid variable always wins and that the rigid variable is a subset of the flex variable. There was also a bug in unifyRigid where the rigid variable would not win! The flex one would win. This accounted for some fraction of the bugs as well. I also try to avoid allocating new rigid content in unifyRigid to maybe make things a bit faster. Fixes #1268 Fixes #1270 Fixes #1281 Fixes #1316 Fixes #1422 Fixes #1581
Has there been a regression in this bug since the May 11, 2017 fix referenced above? I am getting the following error message when trying to implement a comparison function with a
|
@stevensonmt, there hasn't been a release of the compiler between May 2017 and now (actually, between November 2016 and now), so unless you are using an unreleased version of the compiler, you are not having that fix in the compiler on your machine. |
ah, got it. Thanks. |
This program should successfully type-check:
But it is rejected by 0.16 at http://elm-lang.org/try.
The error message is:
But
number
s arecomparable
, so one should be allowed to specialize the latter type to the former.The text was updated successfully, but these errors were encountered: