Describe the bug
- use
ContentHashable to hash the content of an HashMap (directly or indirectly)
- update my haskell packages. A new version of
hashable is released, which change the hash function. The order of HashMap is hence changed, and my nicely content hashed object suddently change their hash.
See the instance for HashMap in the code, it uses toList, the order is unspecified.
https://github.com/tweag/funflow/blob/master/cas/hashable/src/Data/CAS/ContentHashable.hs#L361-L369
To Reproduce
main = do
print =<< contentHash $ HashMap.fromList [("hello", 10), ("goodbye", 20)]
Run this code with different version of hashable (You may have to try different keys in the map, or a bigger map, in order to trigger the effect).
Expected behavior
It is impossible to guarantee that the hash won't change, but either:
- Do not expose an instance for a type when it is known that the hash will change systematically on each release of a library as fundamental as
hashable
- (or) sort the values, at the cost of an
Ord, Eq constraints on the keys of the HashMap.
Describe the bug
ContentHashableto hash the content of anHashMap(directly or indirectly)hashableis released, which change thehashfunction. The order ofHashMapis hence changed, and my nicely content hashed object suddently change their hash.See the instance for
HashMapin the code, it usestoList, the order is unspecified.https://github.com/tweag/funflow/blob/master/cas/hashable/src/Data/CAS/ContentHashable.hs#L361-L369
To Reproduce
Run this code with different version of
hashable(You may have to try different keys in the map, or a bigger map, in order to trigger the effect).Expected behavior
It is impossible to guarantee that the hash won't change, but either:
hashableOrd, Eqconstraints on the keys of theHashMap.