
On 26 November 2010 17:18, Maciej Piechotka
On Thu, 2010-11-25 at 16:15 +0000, Thomas Schilling wrote:
and for a data type with constructors C_1 .. C_n
2. hash (C_i x_i1 ... x_iN) = hash i <> hash x_i1 <> ... <> hash x_iN
where <> is the hash combine function (probably (.))
(.) seems to fail type-checking.
Right, sorry, I was actually having a different type in mind. Something like: newtype HashBuilder = HashBuilder { unHB :: Word -> Word } class Hashable a where addHash :: a -> HashBuilder The argument would be the seed. We'd then have: hash :: Hashable a => a -> Word hash a = finaliseHash $ unHB (addHash a) seed where seed = 0xdeadbeef finaliseHash x = ... -- some final mixing operation As Bryan mentioned, though, this does not allow building hashes in parallel. It would also hard-code the hash function. -- Push the envelope. Watch it bend.