Ticket #842 (closed bug: fixed)

Opened 7 years ago

Last modified 4 years ago

pretty-printing bug in Template Haskell library

Reported by: devnull1999@… Owned by:
Priority: normal Milestone:
Component: libraries (other) Version: 6.4.2
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Easy (less than 1 hour)
Test Case: Blocked By:
Blocking: Related Tickets:

Description

It can quickly be seen in ghci but occurs in any compiler using the libraries:

ghci -fth

:module Language.Haskell.TH
runQ [d| foo (Just _) = True|] >>= putStrLn . pprint

foo Data.Maybe.Just _ = GHC.Base.True

Note: the Just term is no longer parenthesized.

Problem is in Language.Haskell.TH.Ppr where

instance Ppr Clause where
    ppr (Clause ps rhs ds) = hsep (map ppr ps) <+> pprBody True rhs
                          $$ where_clause ds

should read:

instance Ppr Clause where
    ppr (Clause ps rhs ds) = hsep (map (pprPat appPrec) ps) <+> pprBody True rhs
                          $$ where_clause ds

because the Clause follows a function name and so is always inside a surrounding function application.

(It also wouldn't hurt to change

instance Ppr Con where
    ppr (NormalC c sts) = ppr c <+> hsep (map pprStrictType sts)
    ppr (RecC c vsts)
        = ppr c <+> braces (hsep (punctuate comma $ map pprVarStrictType vsts))

to

instance Ppr Con where
    ppr (NormalC c sts) = ppr c <+> hsep (map pprStrictType sts)
    ppr (RecC c vsts)
        = ppr c <+> braces (vcat (punctuate comma $ map pprVarStrictType vsts))

just for esthetics. Record fields run off the page very quickly.)

Change History

Changed 7 years ago by simonpj

  • status changed from new to closed
  • resolution set to fixed

Both fixed, thank you.

Simon

Changed 5 years ago by simonmar

  • architecture changed from Unknown to Unknown/Multiple

Changed 5 years ago by simonmar

  • os changed from Unknown to Unknown/Multiple

Changed 4 years ago by simonmar

  • difficulty changed from Easy (1 hr) to Easy (less than 1 hour)
Note: See TracTickets for help on using tickets.