Proposal: Add `Generically` (or `WrappedGeneric`) newtype to GHC.Generics
Alexis King
lexi.lambda at gmail.com
Fri Aug 30 20:11:23 UTC 2019
> On Aug 30, 2019, at 14:33, David Feuer <david.feuer at gmail.com> wrote:
>
> I do have two concerns:
>
> 1. The Genetically instances for base classes will need to move to base as well, including auxiliary classes where those are needed.
Agreed. For context, the existing instances of Generically (apart from the Generic instance, discussed below) are:
(Generic a, Eq (Rep a ())) => Eq (Generically a)
(Generic a, Ord (Rep a ())) => Ord (Generically a)
(Generic a, GBounded (Rep a)) => Bounded (Generically a)
(Generic a, GEnum StandardEnum (Rep a)) => Enum (Generically a)
(Generic a, GShow0 (Rep a)) => Show (Generically a)
(Generic a, Semigroup (Rep a ())) => Semigroup (Generically a)
(Semigroup a, Generic a, Monoid (Rep a ())) => Monoid (Generically a)
I think having these in `base` is actually a good thing, since it serves as a good set of examples of how to use GHC.Generics. The current `GEnum` class might be a little too much to include in `base`, but that’s fine: it can be specialized to `GEnum StandardEnum` without breaking backwards-compatibility with `generic-data` (which can continue to provide the more sophisticated implementation).
> 2. The Generic instance of Generically is currently a custom job. That's really not the greatest situation in general. Is that essential for some reason? If not, I think its Generic instance should just be derived.
This is an interesting point. Again for context, the current instance is as follows:
instance Generic a => Generic (Generically a) where
type Rep (Generically a) = Rep a
to = Generically . to
from = from . unGenerically
Which is to say `Generically` wrappers are invisible from the perspective of the `Generic` class.
Personally, I think this instance makes sense: think of every instance of some class `C` on `Generically a` is supposed to provide an instance of `C a` in terms of `Generic a`, and that is exactly what `Generic (Generically a)` does. However, it’s obviously a useless instance, since it’s just the identity function on an existing `Generic a` dictionary. In any case, I think it’s harmless, but I can understand why you might think it’s sketchy.
More information about the Libraries
mailing list