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

Types passed to a higher-order function can get mixed up. #123

Closed
dimvar opened this issue Nov 25, 2014 · 6 comments · May be fixed by enterstudio/flow#21 or enterstudio/flow#22
Closed

Types passed to a higher-order function can get mixed up. #123

dimvar opened this issue Nov 25, 2014 · 6 comments · May be fixed by enterstudio/flow#21 or enterstudio/flow#22

Comments

@dimvar
Copy link
Contributor

dimvar commented Nov 25, 2014

Here, Flow warns that boolean and number are incompatible. Also, it warns that we may be passing a string to minus.

function app(f, x) {
  return f(x);
}
var call1 = app(function(x) { return x - 1; }, 123);
var call2 = app(function(x) { return x ? 'qwer' : 'adsf'; }, false);
call1 - 5;
@avikchaudhuri
Copy link
Contributor

Same issue of Flow's inference not being polymorphic enough. Seems like we need to incorporate your CFA2 work into our analysis! :)

@dimvar
Copy link
Contributor Author

dimvar commented Nov 26, 2014

I didn't realize that Flow analyzes function calls context insensitively, and that one has to annotate explicitly for polymorphism. Thanks for the tip, it explains a lot in my examples.

@ghost
Copy link

ghost commented Aug 4, 2015

Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed.

@gcnew
Copy link

gcnew commented Dec 9, 2016

Is the following another instance of this issue?

function flip<A, B, R>(f: (a: A, b: B) => R): (b: B, a: A) => R {
    return (b, a) => f(a, b);
}

function fconst<A, B>(x: A, _: B): A {
    return x;
}

const g = flip(fconst);
const a1: string = g(1, "hello"); // error
const a2: number = g("hello", 1); // error

@SamChou19815
Copy link
Contributor

Flow decides to require annotation for polymorphic functions a long time ago.

@SamChou19815 SamChou19815 closed this as not planned Won't fix, can't repro, duplicate, stale Jul 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants