Skip to content

TH pretty-printer of GADT declarations misprints short constructor lists

Summary

If the total length of GADT data constructor declarations is shorter than 80 characters or thereabouts, the Language.Haskell.TH.Ppr.pprint will put them in the same line, space-separated. This is very wrong because these constructors are part of a block context and can't be parsed in a single line, unless they're separated by semicolon.

Steps to reproduce

$ ghci-9.2.1
GHCi, version 9.2.1: https://www.haskell.org/ghc/  :? for help
ghci> :set -XTemplateHaskell -XGADTs
ghci> Language.Haskell.TH.runQ [d| data MyData where { D1 :: Int -> MyData; D2 :: Bool -> MyData } |] >>= putStrLn . Language.Haskell.TH.Ppr.pprint
data MyData_0 where
    D1_1 :: GHC.Types.Int -> MyData_0
    D2_2 :: GHC.Types.Bool -> MyData_0
ghci> Language.Haskell.TH.runQ [d| data MyData where { D1 :: MyData; D2 :: Bool -> MyData } |] >>= putStrLn . Language.Haskell.TH.Ppr.pprint
data MyData_0 where
    D1_1 :: MyData_0 D2_2 :: GHC.Types.Bool -> MyData_0

Expected behavior

ghci> Language.Haskell.TH.runQ [d| data MyData where { D1 :: MyData; D2 :: Bool -> MyData } |] >>= putStrLn . Language.Haskell.TH.Ppr.pprint
data MyData_0 where
    D1_1 :: MyData_0
    D2_2 :: GHC.Types.Bool -> MyData_0

Mind you I don't see why the type and constructors should be renamed in the output either; they're not free variables.

Environment

  • GHC version used: 9.2.1
Edited by Mario
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information