I was messing around with HashMap and tried to use a Data.Bson.ObjectId as a key. I, of course, discovered that there is not a Hashable instance for that structure. That’s ok, because writing one is trivial.1
instance Hashable ObjectId where hash (Oid x y) = hash (x,y)
I typed that line into GHCi and was told “parse error on input `instance'”. This actually makes sense as the GHCi prompt operates as if the lines were being typed into a do block in the IO monad and an instance can not be defined in this context.
My question then, is there a way to define a new instance within GHCi?
1 Why this instance is not provided by the library is another matter. I would believe the answer was to limit dependencies except that the bson package already depends on everything under the sun.
The good news: Yes, there is a way to define a new instance within GHCi.
The bad news: At the moment, the first step in doing so is “install a development snapshot of GHC”.
This has been an obvious bit of missing functionality in GHCi for quite a while. There was no inherent reason for it to be absent, but I assume it was somewhat difficult to implement and so it got set aside.
However, it seems that as of version 7.4.1, it’s now available:
Whether you think having that right now worth the hassle of installing a non-release version of GHC is up to you.