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

clashing HKT tag inferences glossed over #19871

Closed
KiaraGrouwstra opened this issue Nov 9, 2017 · 2 comments
Closed

clashing HKT tag inferences glossed over #19871

KiaraGrouwstra opened this issue Nov 9, 2017 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@KiaraGrouwstra
Copy link
Contributor

Minimum repro based on gcanti/fp-ts#204 (comment), also featuring @gcanti's HKT hack from #1213 (comment).

TypeScript Version: 2.6.1-insiders.20171019 (Playground)

Code

interface Applicative<F> {}

interface HKT<URI, A> {
  _URI: URI
}

interface Either<L, A> {
  _URI: 'Either'
}
let right: <L, A>(a: A) => Either<L, A>

interface Option<A> {
  _URI: 'Option'
}
let some: <A>(a: A) => Option<A>
let option: Applicative<'Option'>

// 'curried' version
declare function traverse1<F>(F: Applicative<F>): <A, B>(f: (a: A) => HKT<F, B>) => any
let x1 = traverse1(option)(a => some(a)) // HKT<"Option", number[]>
let x2 = traverse1(option)(a => right(a)) // error :)

// uncurried version
declare function traverse2<F, A, B>(F: Applicative<F>, f: (a: A) => HKT<F, B>): any
let x3 = traverse2(option, a => right(a)) // no error :(, HKT<"Option" | "Either">

Expected behavior: error, probably by intersecting the forward/backward inferences into "Option" & "Either" then realizing there is no valid intersection.

Actual behavior: forward and backward tag inferences are reconciliated as "Option" | "Either", causing the x3 to (erroneously) pass.

@SimonMeskens
Copy link

I wonder if this has been looked at yet

@mhegazy mhegazy added the Needs Investigation This issue needs a team member to investigate its status. label Jul 18, 2018
@RyanCavanaugh
Copy link
Member

Picking the largest type among the inference candidates is foundational to the inference algorithm. You'd want #14829 to make the second reference to F be excluded from the candidate set.

@RyanCavanaugh RyanCavanaugh added Duplicate An existing issue was already created and removed Needs Investigation This issue needs a team member to investigate its status. labels Sep 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants