class Eq a where
(==), (/=) :: a -> a -> Bool
x /= y = not (x == y)
x == y = not (x /= y)
deriving instance Eq Bool
I assume it generates
instance Eq Bool where
True == True = True
False == False = True
But how do I create a instance from something like
newtype Sink p = Sink {unSink :: MVar (E.Iteratee (Message p) IO ())}
instance Eq (Sink p) where
?==? = True
Do I just use deriving and ghc will figure out itself?
deriving instance Eq (Sink p)
PS I have read this but it goes beyond my capabilities of understanding
http://www.haskell.org/ghc/docs/7.6.1/html/users_guide/deriving.html
Yes, that will work since there is an instance
Eq (MVar a)that tests whether toMVars are the same [1]. The derived instance forSinkwill use that. However this might not be what you want since theEqinstance doesn’t compare the contents of theMVars, only whether they are the sameMVarin memory.The answer to your question
is probably “No, you must write an instance that has the properties that you want.”