Skip to content

deriving Show adds extra parens for constructor with record syntax

Since record construction binds more tightly than function application, no parentheses are needed when passing a constructor with record syntax to a function constructor. As a result, we can pass Just A {x = 5} as shown below.

module Main where

data A = A {x :: Int} deriving (Show)

main :: IO ()
main = print $ Just A {x = 5}

But we get the result in the GHCi session below:

*Main> main
Just (A {x = 5})

I tried looking through TcGenDeriv, but didn't figure out quite where the parenifying was done. nested_compose_Expr? show_thingies?

I just wanted to make a ticket for general knowledge. Of course, this is not a real bug. Perhaps you could reclassify it as a feature. Either way, it would be nice to have.

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