Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#10819 closed feature request (fixed)

Can't generate data decls deriving multiparam type classes with TH

Reported by: spinda Owned by: spinda
Priority: normal Milestone: 8.0.1
Component: Template Haskell Version: 7.10.2
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: th/T18019.hs
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D1202
Wiki Page:


This applies to both data declarations and (more commonly) newtypes. Example:

{-# LANGUAGE GeneralizedNewtypeDeriving #-}

newtype T a = X { unT :: State Int a } deriving (MonadState Int)

The newtype declaration is impossible to express in Template Haskell's AST, as the field for the derived classes is [Name] when it should really be Cxt.

A workaround is to generate a StandaloneDerivD for each derived multiparam class, but this requires that the user enable the StandaloneDeriving extension which can be unintuitive, especially as there's no way (as far as I can tell) to detect whether this extension is enabled and report a proper error message if it isn't.

Change History (4)

comment:1 Changed 4 years ago by spinda

Differential Rev(s): Phab:D1202
Owner: set to spinda
Test Case: th/T18019.hs

comment:2 Changed 4 years ago by Ben Gamari <ben@…>

In 04ab55d9/ghc:

Use Cxt for deriving clauses in TH (#10819)

Deriving clauses in the TH representations of data, newtype, data
instance, and newtype instance declarations previously were just [Name],
which didn't allow for more complex derived classes, eg. multi-parameter

This switches out [Name] for Cxt, representing the derived classes as
types instead of names.

Test Plan: validate

Reviewers: goldfire, spinda, austin

Reviewed By: goldfire, austin

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #10819

comment:3 Changed 4 years ago by bgamari

Resolution: fixed
Status: newclosed

comment:4 Changed 4 years ago by thomie

Milestone: 8.0.1
Note: See TracTickets for help on using tickets.