Shortcut for declaring standalone deriving instances
- asarpeshkarOP
It would be nice to have a more compact way to declare standalone deriving instances for polymorphic types.
newtype Foo a = Foo a deriving instance Eq a => Eq (Foo a) deriving instance Show a => Show (Foo a)Is there such a shortcut? The declarations above are completely mechanical and get a bit tedious to read, especially when you’re defining multiple such types in close proximity.
- cocreature 1
You don’t need to use standalone deriving at all here. The following does the trick:
newtype Foo a = Foo a deriving (Show, Eq) - asarpeshkar 1
Weird, I could’ve sworn that the compiler complained in similar cases, but maybe I was thinking of examples where the instance type was different from context, e.g
Eq a => Foo [a]or some such. Problem solved then, thanks. - Ben_M
Hi @asarpeshkar If @cocreature was able to resolve your query completely, you can mark his post as the
Solution, this helps in housekeeping on the forum.