[Haskell-cafe] ANN: unordered-containers - a new, faster hashing-based containers library
Emil Axelsson
emax at chalmers.se
Wed Feb 23 14:36:53 CET 2011
2011-02-23 13:56, Victor Nazarov skrev:
> Also I think that value of hash functions is obviously a Monoid and it
> will be convenient to have Monoid instance
>
> newtype Hash = Hash Int
> instance Monoid Hash where
> mempty = Hash 0
> Hash a `mappend` Hash b = Hash (a `combine` b)
>
> class Eq a => Hashable a where
> hash :: a -> Hash
> hashWithSalt :: Hash -> a -> Hash
>
> hashWithSalt salt x = salt `mappend` hash x
Monoid would be a good idea if combine was associative :)
Prelude Data.Hashable> let a = hash "a"
Prelude Data.Hashable> let b = hash "b"
Prelude Data.Hashable> let c = hash "c"
Prelude Data.Hashable> (a `combine` b) `combine` c
198573605
Prelude Data.Hashable> a `combine` (b `combine` c)
177445
/ Emil
More information about the Haskell-Cafe
mailing list