Opened 6 years ago

Closed 6 years ago

#5508 closed bug (fixed)

Template Haskell -ddump-splices lambda pretty printing bug

Reported by: mgsloan1 Owned by:
Priority: normal Milestone:
Component: Template Haskell Version: 7.2.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect warning at compile-time Test Case: th/T5508
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


Parentheses are not placed around lambda expressions when dumping template haskell splices.

One strange thing about this bug is that it only occurs when using "-ddump-splices", and not when using Language.Haskell.TH.Ppr.pprint

x = mkName "x"

thb = QuasiQuoter (const [| $(return . LamE [VarP x] $ VarE x) . id |])
                  undefined undefined undefined 
ghci THPrettyBug.hs -ddump-splices -XQuasiQuotes
GHCi, version 7.2.1:  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
[1 of 1] Compiling Main             ( THPrettyBug.hs, interpreted )
Ok, modules loaded: Main.
*Main> [thb| |]
Loading package pretty- ... linking ... done.
Loading package array- ... linking ... done.
Loading package containers- ... linking ... done.
Loading package template-haskell ... linking ... done.
<interactive>:0:1-8: Splicing expression
    " " ======> (\ x -> x . id)

    No instance for (Show (c0 -> c0))
      arising from a use of `print'
    Possible fix: add an instance declaration for (Show (c0 -> c0))
    In a stmt of an interactive GHCi command: print it

Attachments (1)

THPrettyBug.hs (398 bytes) - added by mgsloan1 6 years ago.

Download all attachments as: .zip

Change History (2)

Changed 6 years ago by mgsloan1

Attachment: THPrettyBug.hs added

comment:1 Changed 6 years ago by simonpj

Resolution: fixed
Status: newclosed
Test Case: th/T5508

Thanks for reporting this. Fixed by

commit 3f5c0ad5d33096f4a8cd33217c3be7c32a7943b3
Author: Simon Peyton Jones <>
Date:   Thu Sep 29 16:57:16 2011 +0100

    Fix parenthesisation in conversion from TH.Exp to HsExpr.HsExpr
    We need to generate enough parens so that -ddump-splices is
    correct Haskell.  There is certainly further to go.


 compiler/hsSyn/Convert.lhs |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

The new output looks like

T5508.hs:(9,9)-(11,28): Splicing expression
    do { let x = mkName "x"
             v = return (LamE [VarP x] $ VarE x);
         [| $v . id |] }
    ((\ x -> x) . id)


Note: See TracTickets for help on using tickets.