logo       

[GHC] #779: small bugs in Language.Haskell.TH.Ppr.pprint: msg#00112

lang.haskell.glasgow.bugs

Subject: [GHC] #779: small bugs in Language.Haskell.TH.Ppr.pprint

#779: small bugs in Language.Haskell.TH.Ppr.pprint
----------------------------------------+-----------------------------------
Reporter: skata@xxxxxxxxxxxxxxxxxxx | Owner:
Type: bug | Status: new
Priority: normal | Milestone: 6.4.2
Component: Template Haskell | Version: 6.5
Severity: minor | Keywords:
Difficulty: Easy (1 hr) | Architecture: Multiple
Os: Multiple |
----------------------------------------+-----------------------------------
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)[[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:_ | c `elem`
"!#$%&~=|+*<>?-^@:./\\"`[[BR]]
`+ -> 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,

--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/779>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@xxxxxxxxxxx
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise