Closed fumieval closed 4 years ago
The fact that GShow
et al. aren't compatible with existing instances is by design, as these classes are primarily intended for educational purposes. That is, they exist to demonstrate how one can define GHC.Generics
-based defaults for common type classes, without actually having to use the original type classes themselves. This has a number of advantages:
GHC.Generics
-based default for Show
that accurately captures all of the intricacies of deriving Show
is quite involved, but since we're using GShow
, not Show
, we are permitted to make some simplifications, at the expense of being slightly less faithful to the "reference implementation" of deriving Show
.generic-deriving
includes (e.g., GSemigroup
) correspond to base
classes (e.g., Semigroup
) that were only introduced to base
relatively recently. Having to support the original Semigroup
in generic-deriving
would complicate generic-deriving
's library dependencies and GHC support window. With GSemigroup
, however, we can bypass that altogether: generic-deriving
can continue to have minimal dependencies and an extremely wide GHC support window. (The latter is important because people often use generic-deriving
as a a way to backport GHC.Generics
features to old versions of GHC.)For these reasons, I usually recommend that people use generic-data
rather than generic-deriving
if they want GHC.Generics
-based defaults for Semigroup
, Show
, etc. that use type classes from base
.
Admittedly, the documentation for generic-deriving
doesn't communicate this very well at the moment.
I've attempted to improve the documentation about this in #73.
I see, thanks for explanation. I'm content as long as the purpose is documented
This package has its own definitions of typeclasses (
GShow
,GMonoid
, etc), but they are often not viable because they are incompatible with the existing instances. For example you can't deriveGShow
of a datatype if it contains a field that's an instance ofShow
but notGShow
.Same goes for everything else. Default method definitions are no longer a reason to redefine classes, now that we have
DerivingVia
.