[Haskell-cafe] How to show record syntax?

Edward Kmett ekmett at gmail.com
Thu Nov 19 10:02:06 EST 2009


Just an aside, derived Show doesn't try to be truly minimal with respect to
superfluous ()'s at this point, for instance it doesn't take into
consideration that when using infixl or infixr you can elide them on one
side, so there is already a precedent for the fact that the ()'s that get
used are not minimal.

That said, I think there is nothing wrong with using the fact that records
bind tighter than application, and 'fixing the grammar' to prevent that
would break a fair bit of code -- I know that I for one use it fairly often.
So, I'm not in favor of proposing a breaking change to the grammar for
Haskell' that removes this functionality.

Eliding the superfluous parens around records in derived Show feels like the
right solution as it imparts less noise in the output.

A very minor concern would be making sure that Read can handle input with or
without the superfluous parentheses, but as I understand things that should
come more or less for free, given that they just wrap the value.

This would let values that were serialized on an older version continue to
be read in the current version, for people who are using Show as a data
storage format.

-Edward Kmett

On Tue, Nov 17, 2009 at 11:14 AM, Sean Leather <leather at cs.uu.nl> wrote:

> 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
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20091119/56bb8c6f/attachment.html


More information about the Haskell-Cafe mailing list