Opened 5 years ago

Closed 2 years ago

#9453 closed bug (fixed)

The example for GHC Generics is kinda broken

Reported by: Feuerbach Owned by: dreixel
Priority: normal Milestone: 8.4.1
Component: Documentation Version: 7.8.2
Keywords: Generics Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Documentation bug Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D3782
Wiki Page:



The popular GHC.Generics serialization example at illustrates how to serialize a sum datatype (a :+: b), with a 0 bit representing a and a 1 bit representing b. However, consider a :+: b :+: c. If the compiler treats this as (a :+: b) :+: c, then a is 00, b is 01, c is 1. If it's a :+: (b :+: c), then a is 0, b is 10, c is 11. The compiler's decision, even though (as I understand it) consistent for any given compile, could differ later. The manual, at states not to depend on the ordering, which the example does.

I think this is a valid concern, and the manual should be at least updated to discuss this problem.

Change History (10)

comment:1 Changed 5 years ago by simonpj

Owner: set to dreixel

Assigning to Pedro: would you care to comment/fix?


comment:2 Changed 5 years ago by dreixel

Yes; certainly if the way the compiler nests sums in the automatic derivation of Generic instances changes, or if the user is giving their own instances, there is no guarantee that the serialisation outcome is the same. I could perhaps add a note to the example in the manual to highlight the fact that it doesn't try to work across different versions of the compiler. Updating the example to deal with different nestings would be overkill, I think.

comment:3 Changed 5 years ago by thomie

Milestone: 7.10.1
Type of failure: None/UnknownDocumentation bug

comment:4 Changed 5 years ago by thoughtpolice


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:5 Changed 4 years ago by thoughtpolice


Milestone renamed

comment:6 Changed 4 years ago by simonpj

Keywords: Generics added

comment:7 Changed 4 years ago by thomie

Milestone: 8.0.1

comment:8 Changed 2 years ago by RyanGlScott

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

comment:9 Changed 2 years ago by Ryan Scott <…>

In 88f20bd/ghc:

Add a caveat to the GHC.Generics examples about :+: nesting

GHC's choice in how it nests `:+:` can sometimes affect the
implementaiton of `GHC.Generics`-related code, so we should make a note of
this in the examples we provide. Fixes #9453.

Test Plan: Read it, like it, build it, ship it

Reviewers: bgamari, austin, hvr

Reviewed By: bgamari

Subscribers: rwbarton, thomie

GHC Trac Issues: #9453

Differential Revision:

comment:10 Changed 2 years ago by RyanGlScott

Milestone: 8.4.1
Resolution: fixed
Status: patchclosed
Note: See TracTickets for help on using tickets.