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

Obscure definition problem #73

Closed
ivan-kleshnin opened this issue Jul 18, 2016 · 4 comments
Closed

Obscure definition problem #73

ivan-kleshnin opened this issue Jul 18, 2016 · 4 comments

Comments

@ivan-kleshnin
Copy link

ivan-kleshnin commented Jul 18, 2016

This code is ok, but does not compile

let filterMatrix = function (v: number, m: Array<Array<number>>): Array<number> {
  return chain(filter((c) => c == v), m)
}

let b = [
  [0, 1],
  [1, 0]
]

console.log(filterMatrix(1, b)) // --> [1, 1]

I'm getting this

TSError: ⨯ Unable to compile TypeScript
src/board.ts (11,10): Type '{}[]' is not assignable to type 'number[]'.
  Type '{}' is not assignable to type 'number'.
@ivan-kleshnin
Copy link
Author

ivan-kleshnin commented Jul 18, 2016

Error disappears if no currying is present.

// compiles
let filterMatrix = function (v: number, m: Array<Array<number>>): Array<number> {
  return chain((r) => filter((c) => c == v, r), m)
}

Mapping compiles as it should so I guess the problem is with filter definition but I failed to find it

// also compiles
let mapMatrix = function (fn, m: Array<Array<number>>): Array<number> {
  return chain(map((c) => fn(c)), m)
}

@KiaraGrouwstra
Copy link
Member

Your hunch was right: the curried filter definition had an issue. Just now it used filter<T>(pred: Pred<T>): <T>(list: List<T>) => T[];, which should have been filter<T>(pred: Pred<T>): (list: List<T>) => T[];.

Note that in the former version the generic was redefined halfway through (no longer the same T!), as a result of which the type variables failed to link up.
Having fixed that, your example type-checks presuming you allow it to find the parameter type for (c) => c == v, using (c: number) => c == v or R.equals(v).

This helped me track down a bunch of related cases of duplicate generics as well. Thank you for reporting this! In fact, this is making me reconsider the 'solution' to #90...

@ivan-kleshnin
Copy link
Author

@tycho01 thanks for taking time to fix this!

@KiaraGrouwstra
Copy link
Member

You're welcome; thank you for your helpful bug reports. :)

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