[Haskell-cafe] How to show record syntax?

Sean Leather leather at cs.uu.nl
Tue Nov 17 11:14:16 EST 2009


A while back, I was working on the Show function for EMGM [1] and verifying
its output vs. that of GHC's when I discovered (I thought) a minor
difference between what was necessary and what GHC did for record syntax.
Labeled construction and update, according to the Report [2], have higher
precedence than function application. This means that I can do the following

> module Main where
> data A = A {x :: Int} deriving Show
> main = print $ Just A {x = 5}

without putting parentheses around A {x = 5}. If I run this in GHCi,

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

I see that the derived show in GHC adds parentheses around the record value.

This led to an issue report [3] which developed a few responses. Some don't
like the grammar as defined, because, at a glance, it appears too much like
function application. Others noted that Hugs does not add the parentheses
and wanted to see consistency between compilers.

In the spirit of the GHC Bug Sweep [4] and finding resolution, I put the
question to the wider community. How should we show record syntax? Should we
try to ensure consistency between the compilers? Should we try to print as
few parentheses as possible? Should we write a Haskell' proposal to "fix"
the grammar and make Just A {x=5} illegal? What do you think?

[1]
http://hackage.haskell.org/packages/archive/emgm/0.3.1/doc/html/Generics-EMGM-Functions-Show.html
[2] http://www.haskell.org/onlinereport/exps.html#sect3
[3] http://hackage.haskell.org/trac/ghc/ticket/2530
[4] http://hackage.haskell.org/trac/ghc/wiki/BugSweep

Regards,
Sean
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20091117/450a2dce/attachment.html


More information about the Haskell-Cafe mailing list