deriving-via-fun is a library for deriving instances by treating classes like functors.
First, define some type, for example:
data T0 = T0 Int Bool
We can reuse existing instances for (Int, Bool) to derive instances for T0, by providing a function T0 -> (Int, Bool). A handy one you can find in the library is the “generic isomorphism” T0 ?-> (Int, Bool).
deriving (Eq, Ord) via Fun (T0 ?-> (Int, Bool))
For another example, let’s derive the All monoid (aka. (&&)) from Any (aka. (||)) by duality:
newtype All = All Bool
deriving (Semigroup, Monoid)
via Fun (Coerce All Bool >>> Not >>> Coerce Bool Any)
deriving-via-fun is available on Hackage. See the README and the haddocks for more details.