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

Type-checking bug: comparable vs. number #1270

Closed
jvoigtlaender opened this issue Jan 29, 2016 · 5 comments
Closed

Type-checking bug: comparable vs. number #1270

jvoigtlaender opened this issue Jan 29, 2016 · 5 comments

Comments

@jvoigtlaender
Copy link
Contributor

Short version:

Should the following program type-check?

f : comparable -> comparable
f _ = 0

I don't think so, but the current compiler accepts that program.

Long version:

If I have a module B defining and exporting some function f : comparable -> comparable, should I be able to use it as follows in another module?

module A where

import B exposing (f)

test = f 'a'

I think so. After all, 'a' is a Char, and type Char is comparable, so 'a' should be a valid input for any function of type comparable -> comparable. However, the following module breaks that expectation:

module B where

f : comparable -> comparable
f _ = 0

And down goes separate compilation. (Module B on its own compiles, so the compiler asserts that the f in there really has type comparable -> comparable. Module A should compile under the assumption that f has type comparable -> comparable. But modules A and B together do not compile.)

@jvoigtlaender
Copy link
Contributor Author

It's possible that this is somehow the same bug, or has the same root cause, as #1268.

@mgold
Copy link
Contributor

mgold commented Jan 29, 2016

What should happen is that 0 : number is unified with the second comparable, which causes the first comparable to be unified with number, resulting in an inferred type of number -> number. The annotation should then be rejected as too general.

I think the larger problem is that we have these three not-quite-type-classes hacked into the language, and so edge cases like this one arise. It might have to wait until implicit parameters or whatever not-type-classes language feature comes along. That is, even if you manage to fix this bug without causing regressions, it might not be worth it if something big comes along in 0.19.

@jvoigtlaender
Copy link
Contributor Author

For a start, I'd like to know whether @evancz agrees this is a bug.

@evancz
Copy link
Member

evancz commented Feb 12, 2016

I think so. comparable should be too general.

@evancz evancz mentioned this issue May 12, 2016
4 tasks
@evancz
Copy link
Member

evancz commented May 12, 2016

Centralizing into #1373, will track from there.

@evancz evancz closed this as completed May 12, 2016
evancz added a commit that referenced this issue May 11, 2017
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants