Hi everybody!
I have just released a handy package on Hackage that will interest you if
you've ever used unordered-containers with a custom type.
In order to do such a thing, you'd need to define an instance of Hashable.
This process could easily be automated.
And so I did.
{-# LANGUAGE DeriveGeneric #-}
module ThisIsPrettyNeat where
import Data.Hashable.Generic
import GHC.Generics
data MyCoolType a = MCT0 | MCT1 (Either Int a) | MCT2 (MyCoolType a)
(MyCoolType a)
deriving Generic
instance Hashable a => Hashable MyCoolType where
hashWithSalt s x = gHashWithSalt s x
{-# INLINEABLE hashWithSalt #-}
and voila. You have a very performant instance of Hashable, with minimal
boilerplate, no template haskell, and no subtle bugs.
If you want to play with it, here it is:
http://hackage.haskell.org/package/hashable-generics-1.1.6
Have fun!
- Clark
Oh yeah, and if anyone wants to help me figure out why it's 1.3x slower
than my hand-rolled instances, that would be really helpful.
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe