I have a couple of classes of the form
class R a b
For the purposes of examples we will use the following simplified class:
class R1 a b where
q :: a -> b -> Bool
Which express some relationship between a and b.
This underlying relationship is commutative, meaning that
R1 a b => R1 b a
where
q a b = not (q b a)
So of course I would like to write an instance that expresses this so I don't have to write nearly every instance twice.
instance R1 a b => R1 b a where
q a b = not (q b a)
This instance is incredibly problematic. Now if I make an instance for R1 I suddenly have an infinite number of (identical) instances for R1. The compiler of course then has no way of knowing which one I want.
Is there a way I can build classes so that I don't have to make two versions of nearly every instance?