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

Hashable type class #189

Closed
wants to merge 7 commits into from
Closed

Conversation

fehrenbach
Copy link

See #188.

@kritzcreek
Copy link
Member

kritzcreek commented Oct 12, 2018

This looks like a great start! I'm assuming you didn't just come up with these hashing functions and took them from somewhere else? (The Haskell implementation? Some paper?)

I think it would be good to have a few comments referencing where these hashing functions are coming from, to have some form of rationale for them.

@fehrenbach
Copy link
Author

The one for Number is used by immutable.js, among others.
Haskell uses identity for Int and fromEnum for "small" types.
The String and Array algorithm here is the same as Java, I think.

I can add comments. It'd be even better if someone did some actual research on the matter. We are in the fortunate position that Eq is homogeneous and there is no subtyping, so changing the algorithm is not a breaking change and can be done for any type individually.

@fehrenbach fehrenbach changed the title Hashable type class, first draft Hashable type class Oct 23, 2018
@fehrenbach
Copy link
Author

This now uses the indexed newtype as discussed in #188.

-- | are never equal. The reverse is not necessarily true.
-- |
-- | Hash values produced by `hash` must not be relied upon to be
-- | stable accross multiple executions of a program and should not be
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: accross -> across

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Hash values of 0 are not uncommon, e.g., 0, false, Nothing, {}, ...
We do not want to hash [true], [false, true], [false, false, true], ... to the same value.
@fehrenbach
Copy link
Author

Thanks to @rightfold for pointing out the array hash problem.

@JordanMartinez
Copy link
Contributor

@fehrenbach Should this PR be closed in favor of #198?

@fehrenbach
Copy link
Author

Yeah, probably. I should get back to this at some point...

@fehrenbach fehrenbach closed this Nov 15, 2020
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

Successfully merging this pull request may close these issues.

4 participants