Skip to content

Template Haskell's Ppr Con instance doesn't handle operator names correctly

Summary

Template Haskell

instance Ppr Con

emits invalid Haskell for operator constructor names. They should be parenthesized.

Steps to reproduce

Here's a runnable test:

{-# Language TemplateHaskell #-}

module PrettyTHBug where

import Language.Haskell.TH

main =  runQ [d| data Operator = (:*) Int |] >>= putStrLn . pprint

The output is

data Operator_0 = :*_1 GHC.Types.Int

Note the operator (:*) has lost the parentheses.

Expected behavior

data Operator_0 = (:*_1) GHC.Types.Int

In fact it would be good to adjust the _1 suffix on the operator as well, but that's not this bug.

Environment

  • GHC version used: 8.10.2

Optional:

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