[Haskell-cafe] Data.Hashable instance generation?
Matti Nykänen
matti.nykanen at uef.fi
Mon Jun 15 08:05:21 UTC 2015
Hello,
A practical question about getting hashing to work.
Having used Data.Map before, I wanted to try Data.HashMap.Lazy instead:
----
{-# LANGUAGE DeriveGeneric #-}
import Data.HashMap.Lazy as HM
import GHC.Generics (Generic)
import Data.Hashable
data Colour = Red | Green | Blue
deriving Generic
instance Hashable Colour
foo = HM.insert Red
----
The data and its instance definition are directly from the web page <https://hackage.haskell.org/package/hashable-1.2.1.0/docs/Data-Hashable.html>.
However, I det the following error:
----
GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling Main ( htest.hs, interpreted )
htest.hs:13:8:
No instance for (hashable-1.1.2.5:Data.Hashable.Hashable Colour)
arising from a use of `insert'
Possible fix:
add an instance declaration for
(hashable-1.1.2.5:Data.Hashable.Hashable Colour)
In the expression: insert Red
In an equation for `foo': foo = insert Red
Failed, modules loaded: none.
----
I do not know what is wrong or how I could fix it.
Note that my Haskell had originally the older hashable-1.0.0 package, but I cabal-installed this hashable-1.1.2.5 because surfing the net suggested that it would be much better. Could it be the case that the instance goes somehow in the wrong class?
--
Matti Nykänen
More information about the Haskell-Cafe
mailing list