Opened 5 years ago

Closed 3 years ago

Last modified 3 years ago

#9526 closed feature request (wontfix)

Add missing Generic instances in base

Reported by: nh2 Owned by: dreixel
Priority: normal Milestone:
Component: Core Libraries Version: 7.8.3
Keywords: Generics Cc: mail@…, hvr, ekmett, heisenbug
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: #10512 Differential Rev(s):
Wiki Page:

Description

Most primitive types (Int, Char, etc.) have a GHC.Generics.Generic instance, but some are missing, such as Integer and the various Word* data types.

We should consistently have instances for all primitive types offered by base, since they are required if you want to derive a Generic instance for any type that contains them.

I boldly set the milestone to 7.10 because I naively assume this should be straightforward.

Change History (15)

comment:1 Changed 5 years ago by nh2

Blocking: 9527 added

comment:2 Changed 5 years ago by dreixel

Owner: set to dreixel

comment:3 Changed 5 years ago by heisenbug

Cc: heisenbug added

comment:4 Changed 5 years ago by dreixel

Actually, I'm thinking that perhaps we should delete the existing Generic instances for base types. They don't really add much; the only thing I can think of is that you can find out the module and datatype name. Other than that, any generic function will still have to provide adhoc behaviour for types such as Int, because there is no generic behaviour for these base types.

Also, this doesn't really block #9527, as far as I can see. You can derive Generic for a datatype that contains Integer, for example, which doesn't have a Generic instance. Things only fail when you try to use a generic function that does not have an instance for Integer.

comment:5 Changed 5 years ago by thoughtpolice

Component: libraries/baseCore Libraries

Moving over to new owning component 'Core Libraries'.

comment:6 Changed 5 years ago by goldfire

Blocking: 9527 removed

comment:7 Changed 5 years ago by thoughtpolice

Milestone: 7.10.17.12.1

Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

comment:8 Changed 4 years ago by thoughtpolice

Milestone: 7.12.18.0.1

Milestone renamed

comment:9 Changed 4 years ago by simonpj

Keywords: Generics added

comment:10 Changed 4 years ago by thomie

Milestone: 8.0.1

comment:11 Changed 3 years ago by RyanGlScott

Resolution: wontfix
Status: newclosed

I'm going to close this for the same reasons that I closed #10512. Please re-open if you feel strongly otherwise.

comment:12 Changed 3 years ago by nh2

I can't tell - I don't really understand the change; link in the ticket description of #9766 seems broken.

Can you explain a bit what this change does, and how it affects this issue? Thanks!

comment:13 Changed 3 years ago by RyanGlScott

Sorry, my bad. I linked the wrong issue. It should be #10512, where Generic instances were proposed for Int32 and Word64. The resolution of that issue is wontfix, and in GHC 8.0, the Generic instances for Char, Float, Double, and Int will be removed.

Pedro outlines the reasons for not including Generic instances for primitive types here. Basically, Generic instances are intended for inspecting the structure of regular, structured algebraic data types until you get down to the "leaves" of a data structure. The leaves only require ad hoc instances of the base class, not of Generic.

Moreover, the previous Generic instances base types were lying to users. Previously, we had something like this:

type Rep Char = D1 D_Char (C1 C_Char (S1 NoSelector (Rec0 Char))

But according to the rules of how Generic operates, that would suggest that data Char = Char Char, which is absolutely not the case. To avoid this dishonesty, we decided to remove the offending instances altogether.

comment:14 Changed 3 years ago by nh2

I think you linked the right issue; I got to #9766 via the git commit you mentioned in #10512.

What you say makes sense, and it does look like a better solution.

I don't know if it addresses all issues that motivated this issue, but your comment at https://ghc.haskell.org/trac/ghc/ticket/10512#comment:7 suggests that it does. I'll try that out when GHC 8 is released with this change, and reopen if there's any remaining problem.

Thanks!

comment:15 Changed 3 years ago by Iceland_jack

Note: See TracTickets for help on using tickets.