Skip to content

TH pretty-printer always emits the single typeclass after the deriving keyword without parentheses

Summary

The keyword deriving is usually followed by a single unparenthesized qualified class name or a parenthesized commma-separated list of classes. With MPTCs, it is also legal to specify a single class with N-1 parameters, but the class and parameters must then be parenthesized. In this situation Language.Haskell.TH.Ppr.pprint doesn't emit parentheses and produces syntactically invalid output.

Steps to reproduce

$ ghci -XMultiParamTypeClasses -XDeriveAnyClass -XTemplateHaskell
GHCi, version 9.6.2: https://www.haskell.org/ghc/  :? for help
ghci> class C a b
ghci> Language.Haskell.TH.runQ [d|data Foo deriving (C a)|] >>= putStrLn . Language.Haskell.TH.Ppr.pprint
data Foo_0 deriving Ghci1.C a_1

Expected behavior

The last line should be

data Foo_0 deriving (Ghci1.C a_1)

Environment

  • GHC version used: 9.6.2

Optional:

  • Operating System:
  • System Architecture:
Edited by Mario
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information