Luke Palmer <[email protected]> writes:

> data Sym = Sym String Hash
>
> fromString :: String -> Sym
> fromString s = Sym s (hash s)
>
> instance Eq Sym where
>     Sym _ h == Sym _ h' = h == h'

> Much as I am uncomfortable with hash-based equality.  1/2^256, despite
> being very small, is not zero.  It is begging for a mysterious failure
> someday.

How about:

  instance Eq Sym where
      Sym s h == Sym s' h' = h == h' && s == s'

So, very fast if the hashes fail to match, only marginally slower than
just the string comparison if they are equal.

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to