Skip to content

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

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.

Trac metadata
Trac field Value
Version 7.10.2
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Template Haskell
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information