Proposal: Add `Generically` (or `WrappedGeneric`) newtype to GHC.Generics

David Feuer david.feuer at gmail.com
Sat Aug 31 01:36:14 UTC 2019


It sounds like we can probably agree not to include the instance for now.
But I don't want to just go with my gut feeling, so here's a concrete
reason:

Generically isn't *just* a DerivingVia target: it's also a perfectly
reasonable newtype in its own right. Consider something like
CoercibleUtils.Newtype [*]. If you try to work `under Generically` with
your instance, then the type checker won't let you. That's rather sad, I
think, because it seems like a perfectly sensible thing to do.

[*]
https://github.com/sjakobi/coercible-utils/blob/072c60837059aaaac47628a1822c01fbb2baed6f/src/CoercibleUtils/Newtype.hs

On Fri, Aug 30, 2019, 8:26 PM Alexis King <lexi.lambda at gmail.com> wrote:

> > On Aug 30, 2019, at 17:26, Alexis King <lexi.lambda at gmail.com> wrote:
> >
> > If you want to leave that instance out, that’s fine with me; I highly
> doubt anyone would miss it. As I said before, it’s totally useless.
>
> Actually, I take this back. It’s not totally useless, just unlikely to be
> useful (and ultimately inessential). It’s theoretically useful if you have
> some function like
>
>      foo :: (Show a, Generic a) => a -> Foo
>
> and want to use the generic version of the `Show` instance, but for some
> reason don’t want to actually define that instance on your type. You can
> write `foo (Generically x)`, and it will work out. That wouldn’t work if
> `Generic (Generically a)` were the derived instance.
>
> On the other hand, you could always get the same behavior in a more
> flexible way by just defining a separate newtype and deriving the relevant
> instances as desired, like this:
>
>      newtype GenericallyShowable a = GenericallyShowable a
>          deriving newtype (Generic)
>          deriving (Show) via Generically a
>
> So the instance isn’t necessary by any means, nor does it seem
> particularly likely to be useful in practice, but it doesn’t seem
> impossible that it ever could be. My vote is to keep it; I don’t see the
> harm.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20190830/15f3535e/attachment.html>


More information about the Libraries mailing list