Skip to content

Document additional guarantee of Arg's Hashable instance #243

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Data/Hashable/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,8 @@ instance Hashable a => Hashable (Max a) where
hashWithSalt p (Max a) = hashWithSalt p a

-- | __Note__: Prior to @hashable-1.3.0.0@ the hash computation included the second argument of 'Arg' which wasn't consistent with its 'Eq' instance.
-- Additionally, as of @hashable-1.3.0.0@, and going forward as part of the API guarantee, the hash of @'Arg' a _@ is the same value as the hash of @a@.
-- This means that it's safe to add and remove 'Arg' from elements stored in hash-indexed data structures without changing any hashes.
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, so this is actually not true.

hashWithSalt salt (Arg x _) = hashWithSalt x by definitiuon, but hash (Arg x _) /= hash x`:

> hash (Nothing :: Maybe Int)
0
> hash (Arg (Nothing :: Maybe Int) 'x')
-5808590958014384161

That is an unfortunate "oversight".

--
-- @since 1.3.0.0
instance Hashable a => Hashable (Arg a b) where
Expand Down