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


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to