Opened 2 years ago

Closed 18 months ago

#10604 closed feature request (fixed)

Make Generic1 kind polymorphic

Reported by: DerekElkins Owned by: RyanGlScott
Priority: low Milestone: 8.2.1
Component: Core Libraries Version: 7.10.1
Keywords: Generics Cc: core-libraries-committee@…, RyanGlScott, ekmett
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: generics/T10604/T10604_*
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D2168
Wiki Page:

Description (last modified by simonpj)

It looks to me that the Generic1 class (and the Rep1 associated type) can immediately be generalized to forall k. k -> *. If k was instantiated to anything other than *, you wouldn't be able to make an instance for Par1, but then I don't think it would ever come up so that would be exactly the right behavior. This allows, in particular, DataKinds to be used as a parameter to instances of Generic1.

I don't know if this would affect deriving, but I wouldn't really expect it to.

Change History (12)

comment:1 Changed 2 years ago by simonpj

Description: modified (diff)

Happily, Andres Loh has agreed to take a lead in Generics and DeriveAnyClass, but only later this summer. Thanks Andres!

comment:2 Changed 2 years ago by dreixel

Do you have any particular use for this?

comment:3 in reply to:  2 Changed 2 years ago by DerekElkins

Replying to dreixel:

Do you have any particular use for this?

I was making a data type parameterized by a data kind because it was built over another data type parameterized by a data kind. This blocked being able to use GHC Generics with the type. In this case, since I controlled the other data type, I just switched it to using empty data types of kind * rather than a data kind, so I'm not blocked by this. If that other data type had been from a library or if data kinds were critical, this wouldn't have been an option.

The Tree type here https://github.com/derekelkins/ads/blob/master/Data/Authenticated/GenericExample.hs was where I ran into the problem when the Auth type was parameterized by a data kind. You can see here, https://github.com/derekelkins/ads/blob/master/Data/Authenticated/Generic.hs, that the Par1 constructor doesn't make sense in my context. In fact, with DataKinds I would not need that comment, because it would simply be illegal to make a type that used Par1. It would be a self-evident kind error rather than a less obvious missing instance error.

comment:4 Changed 2 years ago by ekmett

I have a number of data types for things like McBride-style indexed monads for which I currently can't use Generic support because of this issue. This consequently requires me to laboriously hand-implement support for things like serialization. It seems relatively painless to implement.

comment:5 Changed 2 years ago by thomie

Owner: ekmett deleted

comment:6 Changed 2 years ago by RyanGlScott

Cc: RyanGlScott ekmett added

comment:7 Changed 23 months ago by simonpj

Keywords: Generics added

comment:8 Changed 19 months ago by RyanGlScott

Blocked By: 11837 added
Milestone: 8.2.1
Owner: set to RyanGlScott

I have a patch implementing this that'll work once #11837 is fixed. It isn't going to make it for GHC 8.0, but I'll shoot for 8.2.

comment:9 Changed 19 months ago by RyanGlScott

Differential Rev(s): Phab:D2168
Status: newpatch

comment:10 Changed 19 months ago by Ben Gamari <ben@…>

Blocked By: 11837 removed

comment:11 Changed 19 months ago by Ben Gamari <ben@…>

In b8e25651/ghc:

Make Generic1 poly-kinded

This generalizes the `Generic1` typeclass to be of kind `k -> *`, and
this also makes the relevant datatypes and typeclasses in `GHC.Generics`
poly-kinded. If `PolyKinds` is enabled, `DeriveGeneric` derives
`Generic1` instances such that they use the most general kind possible.
Otherwise, deriving `Generic1` defaults to make an instance where the
argument is of kind `* -> *` (the current behavior).

Fixes #10604. Depends on D2117.

Test Plan: ./validate

Reviewers: kosmikus, dreixel, goldfire, austin, hvr, simonpj, bgamari

Reviewed By: simonpj, bgamari

Subscribers: thomie, ekmett

Differential Revision: https://phabricator.haskell.org/D2168

GHC Trac Issues: #10604

comment:12 Changed 18 months ago by thomie

Resolution: fixed
Status: patchclosed
Test Case: generics/T10604/T10604_*
Note: See TracTickets for help on using tickets.