-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add Hash typeclasses to cats #1690
Comments
-1 on Clone. All should be immutable, so Clone should be a no-op.
+1 on Hash extending Eq.
…On Fri, May 19, 2017 at 11:26 AM Tongfei Chen ***@***.***> wrote:
Hash is a special case of Eq.
These captures the Java default method hashCode and clone (in Cloneable),
just like Eq for equals and Show for toString.
Example implementation:
https://github.com/ctongfei/poly-collection/blob/master/core/src/main/scala/poly/collection/typeclass/Hash.scala#L12
https://github.com/ctongfei/poly-collection/blob/master/core/src/main/scala/poly/collection/typeclass/Cloning.scala#L11
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1690>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEJdmckRku9NOM6G7wGanJk965B4W6Iks5r7gj6gaJpZM4NhCMq>
.
|
Related: typelevel/algebra#38 |
OK. But |
Ditto @johnynek. |
Thanks for the suggestion @ctongfei . Also 👍 on adding |
@kailuowang Thanks. I'll open a PR. |
I propose a Two reasons:
|
this isn't uncommon in cats (see previous discussions #1210). i think the best we have to offer is I personally don't like making the full cross product of possible compositions reified in types. So, I would be |
@johnynek So for each typeclass instance we provide, we will override the |
Can you sketch the case you are worried about? I see the issue with
I see your concern since basically everything has We could use the alternate encoding for trait Hash[A] {
def eqInstance: Eq[A]
def hash(a: A): Int
} so we don't extend, but point to the instance. This would make This keeps coming up. |
I would say the better route is do manual overriding Hash extends Eq has good intuitions: every map requires that there is an |
I drafted a pull request #1712 . |
* cats.kernel.Hash and related instances (#1690) * Hash laws * all test passed * Hash instances for tuples * introduce implicit precedence in KernelBoiler: Order > PartialOrder > Eq; Hash > Eq. * Add type alias in cats._; Add contravariant instance for `Hash` * HashFunctions extends EqFunctions * Move contravariant instances to separate trait, in accordance with (#1659) * revert name change * move EitherInstances1#EitherEq out * Optimize hash computation on case classes without allocating a new object * fixing the problem in CI build: method catsKernelStdOrderForChar()cats.kernel.instances.CharOrder in trait cats.kernel.instances.CharInstances has a different result type in current version, where it is cats.kernel.Order rather than cats.kernel.instances.CharOrder * Full compliance with how Scala generates hash codes on case classes; +SetHash * Cartesian[Hash] * ContravariantCartesian[Hash] * ContravariantCartesian[Hash]; Hash.fromHashing * style issues * remove unused import * some test cases * some test cases * +test for Contravariant[Hash] * +test for Contravariant[Hash] * Add NEL/NEV one (#1707) `NonEmptyList.one` is analogous to `_.pure[NonEmptyList]`. Alternative for `NonEmptyList.of(x)` where you don't pay the price of the varargs, which isn't used. * move instances into separate trait (#1659) * move instances into separate trait * adding separate objects for piecemeal imports * Adding implicit resolution tests for piecemeal imports for hierarchy * Removing explicit implicitly and using apply method * cats.kernel.Hash and related instances (#1690) * Hash laws * all test passed * Hash instances for tuples * introduce implicit precedence in KernelBoiler: Order > PartialOrder > Eq; Hash > Eq. * Add type alias in cats._; Add contravariant instance for `Hash` * HashFunctions extends EqFunctions * Move contravariant instances to separate trait, in accordance with (#1659) * revert name change * move EitherInstances1#EitherEq out * Optimize hash computation on case classes without allocating a new object * fixing the problem in CI build: method catsKernelStdOrderForChar()cats.kernel.instances.CharOrder in trait cats.kernel.instances.CharInstances has a different result type in current version, where it is cats.kernel.Order rather than cats.kernel.instances.CharOrder * Full compliance with how Scala generates hash codes on case classes; +SetHash * Cartesian[Hash] * ContravariantCartesian[Hash] * ContravariantCartesian[Hash]; Hash.fromHashing * style issues * remove unused import * some test cases * some test cases * +test for Contravariant[Hash] * +test for Contravariant[Hash] * cats.kernel.Hash and related instances (#1690) * Hash laws * all test passed * Hash instances for tuples * introduce implicit precedence in KernelBoiler: Order > PartialOrder > Eq; Hash > Eq. * Add type alias in cats._; Add contravariant instance for `Hash` * HashFunctions extends EqFunctions * Move contravariant instances to separate trait, in accordance with (#1659) * revert name change * move EitherInstances1#EitherEq out * Optimize hash computation on case classes without allocating a new object * fixing the problem in CI build: method catsKernelStdOrderForChar()cats.kernel.instances.CharOrder in trait cats.kernel.instances.CharInstances has a different result type in current version, where it is cats.kernel.Order rather than cats.kernel.instances.CharOrder * Full compliance with how Scala generates hash codes on case classes; +SetHash * Cartesian[Hash] * ContravariantCartesian[Hash] * ContravariantCartesian[Hash]; Hash.fromHashing * style issues * remove unused import * some test cases * some test cases * +test for Contravariant[Hash] * +test for Contravariant[Hash] * Fix duplication error and style error * fix merge error * remove instance for Cartesian[Hash]: it does not satisfy associativity * +identityHash, +`hash` postfix method * all tests passed * increase coverage * accidentally removed plugin, restore it * all tests passed * increase coverage * increase coverage, ## => hashCode, kernelBoiler * suppress mimaReportBinaryIssues * Remove cats.functor * Remove cats.functor
Hash
is a special case ofEq
.These captures the Java default method
hashCode
andclone
(inCloneable
), just likeEq
forequals
andShow
fortoString
.Example implementation:
https://github.com/ctongfei/poly-collection/blob/master/core/src/main/scala/poly/collection/typeclass/Hash.scala#L12
https://github.com/ctongfei/poly-collection/blob/master/core/src/main/scala/poly/collection/typeclass/Cloning.scala#L11
The text was updated successfully, but these errors were encountered: