You need to provide a way for ghc to make up that instance. One way to do this is:
{-# LANGUAGE FlexibleContexts, RankNTypes #-}
data STLike s a = STLike a deriving (Eq)
class Box box where
runBox :: box a -> a
newtype Boxed box a = Boxed (box a)
instance (Box box, Eq a) => Eq (Boxed box a) where
Boxed a == Boxed b = runBox a == runBox b
run :: (Eq a, Box box) => (forall s. Eq (Boxed box (STLike s a))
=> box (STLike s a))
-> a
run box = case runBox box of STLike a -> a
I don't think you can have an instance Eq (box (STLike s a))
, so there's a slightly
inconvenient newtype above.