Skip to content

-ddump-splices omits required parentheses when printing view patterns

If you run this program:

{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -ddump-splices #-}
module Bug where

$([d| pattern P x <- (id -> x) |])

You'll get this output:

$ ghc-9.10.1 Bug.hs -dsuppress-uniques -ddump-splices
[1 of 1] Compiling Bug              ( Bug.hs, Bug.o )
Bug.hs:7:2-34: Splicing declarations
    [d| pattern P x <- (id -> x) |] ======> pattern P x <- id -> x

Note that the -ddump-splices output displays pattern P x <- id -> x. This is not valid code, since trying to copy-paste this into a file will make GHC produce a parse error:

$ ghc-9.10.1 Bug.hs
[1 of 1] Compiling Bug              ( Bug.hs, Bug.o ) [Source file changed]
Bug.hs:8:19: error: [GHC-58481]
    parse error on input ‘->’
  |
8 | pattern P x <- id -> x
  |                   ^^

I will investigate.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information