small bugs in Language.Haskell.TH.Ppr.pprint
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[[BR]] Prelude> Language.Haskell.TH.runQ [t| (Int->Int)->Int |] >>= \e -> putStrLn (Language.Haskell.TH.pprint e)[[BR]] Loading package template-haskell-1.0 ... linking ... done.[[BR]] 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)[c `elem` "!#$%&~=|+*<>?-^@:./\\"`[[BR](BR]] 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
[[BR]]
{
[[BR]]
hunk ./Language/Haskell/TH/Ppr.hs 42
[[BR]]
- ppr v = pprName v -- text (show v)
[[BR]]
+ ppr v = case nameBase v of c:_ )
+ -> parens (pprName v)\[\[BR\]\]
+ _ -> pprName v\[\[BR\]\]
hunk ./Language/Haskell/TH/Ppr.hs 289\[\[BR\]\]
-pprTyApp (ArrowT, [arg1,arg2]) = sep [ppr arg1 <+> text "->", ppr arg2]\[\[BR\]\]
+pprTyApp (ArrowT, [arg1,arg2]) = sep [ppr' arg1 <+> text "->", ppr arg2]\[\[BR\]\]
+ where ppr' t = case split t of (ArrowT, [,]) -> parens (ppr t)\[\[BR\]\]
+ _ -> ppr t\[\[BR\]\]
}`[[BR]]
Best regards,
Trac metadata
Trac field | Value |
---|---|
Version | 6.5 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Template Haskell |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | Multiple |
Architecture | Multiple |