Ticket #779 (closed bug: fixed)
small bugs in Language.Haskell.TH.Ppr.pprint
Description
Thank you very much for developing GHC. I would like to report two small bugs and my patch for them.
(These problems apply at least to 6.4.1, 6.4.2, and the current 6.5 in the darcs repository)
Problem 1: pprint does not deal with parentheses of types of higher-order functions correctly, i.e.:
[skata@mermaid]~% ghci -fth -v0
Prelude> Language.Haskell.TH.runQ [t| (Int->Int)->Int |] >>= \e -> putStrLn (Language.Haskell.TH.pprint e)
Loading package template-haskell-1.0 ... linking ... done.
GHC.Base.Int -> GHC.Base.Int -> GHC.Base.Int
I believe '(GHC.Base.Int -> GHC.Base.Int) -> GHC.Base.Int' should be printed.
Problem 2: pprint does not parenthesize operators used as functions, e.g.:
Prelude> Language.Haskell.TH.runQ [| (.) id id |] >>= \e -> putStrLn (Language.Haskell.TH.pprint e)
GHC.Base.. GHC.Base.id GHC.Base.id
I think 'GHC.Base..' should be parenthesized.
Patch: Hopefully the following patch works (at least for me):
== running darcs whatsnew in libraries/template-haskell
{
hunk ./Language/Haskell/TH/Ppr.hs 42
- ppr v = pprName v -- text (show v)
+ ppr v = case nameBase v of c:_ | c elem "!#$%&~=|+*<>?-^@:./\\"
+ -> parens (pprName v)
+ _ -> pprName v
hunk ./Language/Haskell/TH/Ppr.hs 289
-pprTyApp (ArrowT, [arg1,arg2]) = sep [ppr arg1 <+> text "->", ppr arg2]
+pprTyApp (ArrowT, [arg1,arg2]) = sep [ppr' arg1 <+> text "->", ppr arg2]
+ where ppr' t = case split t of (ArrowT, [_,_]) -> parens (ppr t)
+ _ -> ppr t
}
Best regards,

