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

Invalid some incompatible instantiation of a error #1046

Closed
Gozala opened this issue Nov 5, 2015 · 5 comments
Closed

Invalid some incompatible instantiation of a error #1046

Gozala opened this issue Nov 5, 2015 · 5 comments

Comments

@Gozala
Copy link
Contributor

Gozala commented Nov 5, 2015

Here is a simple code example:

/* @flow */

export type Always = <a> (a:a) => () => a
export const always:Always = (a) => () => a

Which produces a following error:

src/flowing.js:4
  4: export const always:Always = (a) => () => a
                                               ^ a. This type is incompatible with
  4: export const always:Always = (a) => () => a
                                  ^^^^^^^^^^^^^^ some incompatible instantiation of a


Found 1 error

Please also note that flow correctly reports type of always:

<a> (a: a) => () => a
/Users/gozala/Projects/flowing/src/flowing.js:4:14,4:26

But if I inline type annotations everything seems to work fine:

/* @flow */

export const always = <a> (a:a):()=>a => () => a

Also note that flow reports same type for always as before:

<a> (a: a) => () => a
/Users/gozala/Projects/flowing/src/flowing.js:3:14,3:19

It maybe same issue as #928 although I'm not totally sure, if so we should probably keep this and close the other one since this has a lot more simpler example

@samwgoldman
Copy link
Member

This is a dupe of #120. The Always type is polymorphic, but Flow doesn't infer polymorphic types. That's why your working example works.

@samwgoldman
Copy link
Member

Sorry, not #120, but rather #123.

@Gozala
Copy link
Contributor Author

Gozala commented Nov 5, 2015

This is a dupe of #120. The Always type is polymorphic, but Flow doesn't infer polymorphic types. That's why your working example works.

So are you implying that flow should error in both cases ? If so mind elaborating on why ? Is it still flow being very cautious about possible mutations that could happen to a ?

@samwgoldman
Copy link
Member

No, this is a real issue, but there's already an open issue for it—Flow doesn't infer polymorphic function types. This is the same reason why this code doesn't work:

function id(x) { return x };
id(0);
id("");

Flow sees the first invocation and the type of f becomes (x: number) => number. After the second invocation, f becomes (x: number | string) => number | string. That is, Flow never realizes that f is actually <T>(x: T) => T.

It should, and that's what Avik meant in the linked issue when he said Flow isn't "polymorphic enough."

@Gozala
Copy link
Contributor Author

Gozala commented Nov 5, 2015

But why does flow reports correct polymorphic type for both implementations of always then ?

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

2 participants