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

Hash[Map[K, V]] has unnecessary constraint #3039

Closed
travisbrown opened this issue Sep 8, 2019 · 8 comments
Closed

Hash[Map[K, V]] has unnecessary constraint #3039

travisbrown opened this issue Sep 8, 2019 · 8 comments
Labels

Comments

@travisbrown
Copy link
Contributor

travisbrown commented Sep 8, 2019

Similar to #3038. Now we have:

  implicit def catsKernelStdHashForMap[K: Hash, V: Hash]: Hash[Map[K, V]] =
    new MapHash[K, V]

But the K: Hash isn't used in the implementation.

@travisbrown travisbrown added the bug label Sep 8, 2019
@vasiliybondarenko
Copy link
Contributor

I'll create PR if nobody minds.

@travisbrown
Copy link
Contributor Author

@vasiliybondarenko Sounds good to me, although the problem is that I don't think it's possible to fix it without breaking bincompat, which means the PR will be have to be parked for a long time.

@kailuowang
Copy link
Contributor

as soon as #3051 gets merged we can fix this right without breaking BC: deprecate the current one and remove the implicit keyword and add a new one without the constraint.

@travisbrown
Copy link
Contributor Author

@kailuowang Oh, I guess that's right—the erasure will be different so the names won't collide.

vasiliybondarenko added a commit to vasiliybondarenko/cats that referenced this issue Sep 13, 2019
vasiliybondarenko added a commit to vasiliybondarenko/cats that referenced this issue Sep 13, 2019
@vasiliybondarenko
Copy link
Contributor

@kailuowang could you take a look at my PR?

@ctongfei
Copy link
Contributor

I'm the author of that function.

Hash[V] is actually used in the implementation: to hash a map, we need to have the hash code for each (K, V) pair, which, in turn, requires an implicit Hash[V].

See the implementation here: https://github.com/typelevel/cats/blob/master/kernel/src/main/scala/cats/kernel/instances/MapInstances.scala#L33

@vasiliybondarenko
Copy link
Contributor

@ctongfei that's right. But we still don't need Hash[K], as key uses Scala's hashCode

@ctongfei
Copy link
Contributor

ctongfei commented Oct 1, 2019

@vasiliybondarenko That is right. Scala's Map uses universal hash code, so Hash[K] is not needed. Thanks for the clarification!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants