Opened 5 years ago

Closed 5 years ago

Last modified 3 years ago

#9527 closed feature request (fixed)

Add Generic instances for Language.Haskell.TH

Reported by: nh2 Owned by: goldfire
Priority: normal Milestone: 7.10.1
Component: Core Libraries Version: 7.8.3
Keywords: Generics Cc: mail@…, hvr, ekmett, core-libraries-committee@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D437
Wiki Page:


Template Haskell has a number of huge data types that would be much easier to work with if they had Generic instances.

Change History (12)

comment:1 Changed 5 years ago by thoughtpolice

Component: libraries/baseCore Libraries
Owner: set to ekmett

Moving over to new owning component 'Core Libraries'.

comment:2 Changed 5 years ago by goldfire

Cc: core-libraries-committee@… added
Owner: changed from ekmett to goldfire

I'm starting some TH work so will take this one.

comment:3 Changed 5 years ago by luite

While you're at it, could you check if adding Binary instances is still problematic? The binary package is not a dependency at the moment. There's a comment in the code about switching to Binary (from Data) for serialization for annotations:

Serialization of the other data types is useful for out-of-process TH currently used by GHCJS, possibly in the future for cross compilation (someone started porting the GHCJS code to GHC but appears to have stopped working on it, I hope i have time to pick this up soon)

Using the default Binary instance based on the GHC.Generics is ok for this purpose and works for almost all types. Here is my list of orphan instances:

NameFlavour requires a handwritten instance because of an Int# field. Can this be changed to a strict Int field?

comment:4 Changed 5 years ago by goldfire

See Design/TemplateHaskellGADTs for a related change to the Dec type I'd like feedback on.

comment:5 Changed 5 years ago by goldfire

An IRC discussion suggests not adding Binary instances:

hvr 1:32 goldfire: well, we only recently dropped the containers dep in template-haskell to not force users wanting to use TH to a specific containers verison hvr 1:32 goldfire: adding dep on 'binary' would be rather undesirable in that respect goldfire 1:32 hvr: That makes sense. 1:33 hvr: Does this get mitigated at all by the Backpack work? hvr 1:33 goldfire: no idea tbh goldfire 1:33 Because my (very loose) understanding is that multiple versions of the same package can now coexist peacefully. 1:34 So, a TH client that doesn't use the Binary instances would be welcome to use a different version of the binary package. 1:34 But, a TH client that wanted to use the TH Binary instances would be tied to the specific version of binary that TH ships with, lest they get type errors. 1:35 ezyang: Care to comment on my and hvr's discussion just now? ezyang 1:46 goldfire, hvr: As with everything, this comes with the caveat that Cabal doesn't know how to handle this, but yes, in principle this is possible with the new change rwbarton 1:47 sounds like it would make sense to wait until 7.12 to add those instances goldfire 1:47 rwbarton: Yes, that's the conclusion I'm coming to. luite: Care to counter? rwbarton 1:48 since the out-of-process TH most likely won't land in 7.10 anyways right?

comment:6 Changed 5 years ago by goldfire

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

comment:7 Changed 5 years ago by goldfire

Differential Rev(s): Phab: D437Phab:D437

comment:8 Changed 5 years ago by Richard Eisenberg <eir@…>

In 1d66167e56317bbd0e06301fe3cbdc40c9c3e34b/ghc:

Remove unboxed Int# fields from NameFlavour (#9527)

comment:9 Changed 5 years ago by Richard Eisenberg <eir@…>

In 88a42be1b40c55241f835da815faa9eb8b356331/ghc:

Derive Generic for TH types (#9527)

comment:10 Changed 5 years ago by goldfire

Blocked By: 9526 removed
Resolution: fixed
Status: patchclosed

comment:11 Changed 5 years ago by Richard Eisenberg <eir@…>

In 786b62aa57e4dcc528e2da2f7d0451ab834d655a/ghc:

Add release notes for #8100, #9527, and #9064.

comment:12 Changed 3 years ago by RyanGlScott

Keywords: Generics added
Note: See TracTickets for help on using tickets.