Skip to content

pretty-printing bug in Template Haskell library

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.)

Trac metadata
Trac field Value
Version 6.4.2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component libraries (other)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system Unknown
Architecture Unknown
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information