proposal for trailing comma and semicolon

There's a weird idiom that I see all the time in Haskell code where coders put commas at the beginning of lines: data Thing = Thing { x :: Int ,y :: Int ,z :: Int ,foo :: String } ... items = [ "red" ,"blue" ,"green" ] and it's pretty clear that the reason for this is that it's easier to comment out the last item by prefixing -- items = [ "red" ,"blue" -- ,"green" ] instead of items = [ "red", "blue" -- , -- "green" ] The same sort of thing shows up with semicolons sometimes too let { x = 1 ;y = 2 ;z = 3 } in However, this punctuation-at-the-front just seems wrong. It ultimately comes from using , as a separator rather than a terminator in the syntax of sequences. But Python has this nifty quirk where you can leave a comma after the last item in a sequence, so that the following is OK in Python but not in Haskell: items = [ "red", "blue", -- "green" ] Part of why Python does this is to allow room in the syntax for tuples with a single item as in (1,) There might be problems doing this with Haskell tuples because of tuple sections like (,,,) building a 4-tuple from 4 arguments, and where (x,y,) is interpreted as a function that takes another item and produces a three-component tuple. Anyway, this is a "paper cut" in the language that has been bugging me for a while, and since there's now a call for suggestions for Haskell 2014, I thought I'd ask about it. -- Garrett Mitchener

On Fri, May 17, 2013 at 9:17 AM, Garrett Mitchener < garrett.mitchener@gmail.com> wrote:
Anyway, this is a "paper cut" in the language that has been bugging me for a while, and since there's now a call for suggestions for Haskell 2014, I thought I'd ask about it.
I've also thought about this issue and I agree with Garrett, allowing that trailing comma (or semicolon) would help readability*. If it doesn't work with tuples, perhaps we could at least do it with lists and records? * It also hurts source control diffs a bit, as adding extra commas will give diffs that suggest that one additional line was changed. -- Johan

On 05/17/2013 06:32 PM, Johan Tibell wrote:
On Fri, May 17, 2013 at 9:17 AM, Garrett Mitchener < garrett.mitchener@gmail.com> wrote:
Anyway, this is a "paper cut" in the language that has been bugging me for a while, and since there's now a call for suggestions for Haskell 2014, I thought I'd ask about it.
I've also thought about this issue and I agree with Garrett, allowing that trailing comma (or semicolon) would help readability*. If it doesn't work with tuples, perhaps we could at least do it with lists and records?
Multiline tuples don't seem all that common, so +1 on that from me.

My main concern is its a really weird corner case for the grammar to
remember for tuple sections and it does have very weird grammar
specification issues.
I really have no objection to it for the other cases. It'd make export
lists cleaner, maybe a few other cases, but how often can you really say
you can meaningfully comment out one field of a tuple have have the
surrounding code make any sense?
-Edward
On Fri, May 17, 2013 at 12:35 PM, Bardur Arantsson
On Fri, May 17, 2013 at 9:17 AM, Garrett Mitchener < garrett.mitchener@gmail.com> wrote:
Anyway, this is a "paper cut" in the language that has been bugging me for a while, and since there's now a call for suggestions for Haskell 2014, I thought I'd ask about it.
I've also thought about this issue and I agree with Garrett, allowing
On 05/17/2013 06:32 PM, Johan Tibell wrote: that
trailing comma (or semicolon) would help readability*. If it doesn't work with tuples, perhaps we could at least do it with lists and records?
Multiline tuples don't seem all that common, so +1 on that from me.
_______________________________________________ Haskell-prime mailing list Haskell-prime@haskell.org http://www.haskell.org/mailman/listinfo/haskell-prime

On Fri, May 17, 2013 at 02:04:44PM -0400, Edward Kmett wrote:
My main concern is its a really weird corner case for the grammar to remember for tuple sections and it does have very weird grammar specification issues.
Tuple sections could look like (True, _) rather than (True,) Does anyone know how common tuple sections are, incidentally? They've been around since GHC 6.12, so it would be interesting to know if people are actually using them.
I really have no objection to it for the other cases. It'd make export lists cleaner,
Actually, you are already allowed an extra trailing comma in import and export lists.
maybe a few other cases, but how often can you really say you can meaningfully comment out one field of a tuple have have the surrounding code make any sense?
It happens occasionally, especially when simplifying code while debugging. Commenting out list items is much more common, though. I'd be in favour of allowing a trailing or leading comma anywhere that comma is used as a separator. TupleSections would need to be changed or removed, though. Thanks Ian -- Ian Lynagh, Haskell Consultant Well-Typed LLP, http://www.well-typed.com/

I personally use tuple sections a fair bit, though admittedly mostly for
simple (,a) or (a,) cases.
On Fri, May 17, 2013 at 3:01 PM, Ian Lynagh
On Fri, May 17, 2013 at 02:04:44PM -0400, Edward Kmett wrote:
My main concern is its a really weird corner case for the grammar to remember for tuple sections and it does have very weird grammar specification issues.
Tuple sections could look like (True, _) rather than (True,)
Does anyone know how common tuple sections are, incidentally? They've been around since GHC 6.12, so it would be interesting to know if people are actually using them.
I really have no objection to it for the other cases. It'd make export lists cleaner,
Actually, you are already allowed an extra trailing comma in import and export lists.
maybe a few other cases, but how often can you really say you can meaningfully comment out one field of a tuple have have the surrounding code make any sense?
It happens occasionally, especially when simplifying code while debugging.
Commenting out list items is much more common, though.
I'd be in favour of allowing a trailing or leading comma anywhere that comma is used as a separator. TupleSections would need to be changed or removed, though.
Thanks Ian -- Ian Lynagh, Haskell Consultant Well-Typed LLP, http://www.well-typed.com/
_______________________________________________ Haskell-prime mailing list Haskell-prime@haskell.org http://www.haskell.org/mailman/listinfo/haskell-prime

I use them sometimes, but would do that much more if they didn't require
adding an extension.
Roman
* Edward Kmett
I personally use tuple sections a fair bit, though admittedly mostly for simple (,a) or (a,) cases.
On Fri, May 17, 2013 at 3:01 PM, Ian Lynagh
wrote: On Fri, May 17, 2013 at 02:04:44PM -0400, Edward Kmett wrote:
My main concern is its a really weird corner case for the grammar to remember for tuple sections and it does have very weird grammar specification issues.
Tuple sections could look like (True, _) rather than (True,)
Does anyone know how common tuple sections are, incidentally? They've been around since GHC 6.12, so it would be interesting to know if people are actually using them.
I really have no objection to it for the other cases. It'd make export lists cleaner,
Actually, you are already allowed an extra trailing comma in import and export lists.
maybe a few other cases, but how often can you really say you can meaningfully comment out one field of a tuple have have the surrounding code make any sense?
It happens occasionally, especially when simplifying code while debugging.
Commenting out list items is much more common, though.
I'd be in favour of allowing a trailing or leading comma anywhere that comma is used as a separator. TupleSections would need to be changed or removed, though.
Thanks Ian -- Ian Lynagh, Haskell Consultant Well-Typed LLP, http://www.well-typed.com/
_______________________________________________ Haskell-prime mailing list Haskell-prime@haskell.org http://www.haskell.org/mailman/listinfo/haskell-prime
_______________________________________________ Haskell-prime mailing list Haskell-prime@haskell.org http://www.haskell.org/mailman/listinfo/haskell-prime

On 17/05/13 20:01, Ian Lynagh wrote:
I'd be in favour of allowing a trailing or leading comma anywhere that comma is used as a separator. TupleSections would need to be changed or removed, though.
The type constructors for tuples look like (,,,), so they would have to be a special case. I'd much rather leave tuples out of it: the precise number of commas in a tuple is significant. Cheers, Simon

On Tue, Aug 13, 2013 at 09:47:49PM +0100, Simon Marlow wrote:
On 17/05/13 20:01, Ian Lynagh wrote:
I'd be in favour of allowing a trailing or leading comma anywhere that comma is used as a separator. TupleSections would need to be changed or removed, though.
The type constructors for tuples look like (,,,), so they would have to be a special case.
Ugh, true.
I'd much rather leave tuples out of it: the precise number of commas in a tuple is significant.
It would be rather unpleasant to have [1,2,3,] :: [Int] (1,2,3,) :: Int -> (Int, Int, Int, Int) Thanks Ian

Hi, Garrett Mitchener wrote:
There's a weird idiom that I see all the time in Haskell code where coders put commas at the beginning of lines:
data Thing = Thing { x :: Int ,y :: Int ,z :: Int ,foo :: String } ...
items = [ "red" ,"blue" ,"green" ]
(I don't think this is valid Haskell. The closing } and ] should be more indented). I like to put commas at the beginning of lines, because there, I can make them line up and it is visually clear that they are all at the same nesting level. I like how the commas look a bit like bullet points. For example, I would write: items = [ "red" , "blue" , "green" ] Could we extend Garett's proposal to also allow prefixing the first element of a list with a comma, to support this style: items = [ , "red" , "blue" , "green" ] Allowing an optional extra comma both at the beginning and at the end would allow programmers the choice where they want to put their commas. Tillmann

I think Tilmann's way is the right way (because it is very clear when a comma is missing since they align, unlike trailing commas), although the original proposal is the popular way. I would rather get rid of commas altogether (make them optional actually) and just have a newline + consistent indentation signal a new list item: coffee-script does that. On Fri, May 17, 2013 at 11:23 AM, Tillmann Rendel < rendel@informatik.uni-marburg.de> wrote:
Hi,
Garrett Mitchener wrote:
There's a weird idiom that I see all the time in Haskell code where coders put commas at the beginning of lines:
data Thing = Thing { x :: Int ,y :: Int ,z :: Int ,foo :: String } ...
items = [ "red" ,"blue" ,"green" ]
(I don't think this is valid Haskell. The closing } and ] should be more indented).
I like to put commas at the beginning of lines, because there, I can make them line up and it is visually clear that they are all at the same nesting level. I like how the commas look a bit like bullet points. For example, I would write:
items = [ "red" , "blue" , "green" ]
Could we extend Garett's proposal to also allow prefixing the first element of a list with a comma, to support this style:
items = [ , "red" , "blue" , "green" ]
Allowing an optional extra comma both at the beginning and at the end would allow programmers the choice where they want to put their commas.
Tillmann
______________________________**_________________ Haskell-prime mailing list Haskell-prime@haskell.org http://www.haskell.org/**mailman/listinfo/haskell-primehttp://www.haskell.org/mailman/listinfo/haskell-prime

On Fri, May 17, 2013 at 11:37:29AM -0700, Greg Weber wrote:
I would rather get rid of commas altogether (make them optional actually) and just have a newline + consistent indentation signal a new list item: coffee-script does that.
I'm interested in this idea. We should make sure we think it through and there are no weird cases, but if it all works out I'd be in favour. This looks a bit too much like a GADT to my eyes: data Point = MkPoint x :: Rational y :: Rational Maybe the recommended style would be: data Point = MkPoint x :: Rational y :: Rational But I suppose pattern-matching, update syntax and so forth would probably still have to use explicit braces and commas. That inconsistency is probably a bit unpleasant. I'd say import and export lists at least are probably fine with a layout-based rule.
On Fri, May 17, 2013 at 11:23 AM, Tillmann Rendel < rendel@informatik.uni-marburg.de> wrote:
Hi,
Garrett Mitchener wrote:
There's a weird idiom that I see all the time in Haskell code where coders put commas at the beginning of lines:
data Thing = Thing { x :: Int ,y :: Int ,z :: Int ,foo :: String } ...
items = [ "red" ,"blue" ,"green" ]
(I don't think this is valid Haskell. The closing } and ] should be more indented).
I like to put commas at the beginning of lines, because there, I can make them line up and it is visually clear that they are all at the same nesting level. I like how the commas look a bit like bullet points. For example, I would write:
items = [ "red" , "blue" , "green" ]
Could we extend Garett's proposal to also allow prefixing the first element of a list with a comma, to support this style:
items = [ , "red" , "blue" , "green" ]
Allowing an optional extra comma both at the beginning and at the end would allow programmers the choice where they want to put their commas.
Tillmann
______________________________**_________________ Haskell-prime mailing list Haskell-prime@haskell.org http://www.haskell.org/**mailman/listinfo/haskell-primehttp://www.haskell.org/mailman/listinfo/haskell-prime
_______________________________________________ Haskell-prime mailing list Haskell-prime@haskell.org http://www.haskell.org/mailman/listinfo/haskell-prime

Greg Weber wrote: I would rather get rid of commas altogether (make them optional actually) and just have a newline + consistent indentation signal a new list item: coffee-script does that.
That would go well together with allowing extra commas, because in explicit block syntax, we can have extra semicolons. Ben Millwood wrote:
This looks a bit too much like a GADT to my eyes:
data Point = MkPoint x :: Rational y :: Rational
I fear that this is confusing, because so far, layout is always introduced by a keyword. But here, layout is introduced by an identifier. I suspect this is also what makes problems below for update syntax etc.
But I suppose pattern-matching, update syntax and so forth would probably still have to use explicit braces and commas. That inconsistency is probably a bit unpleasant.
I feel that record (definition | matching | literals | update) should all use the same syntax.
I'd say import and export lists at least are probably fine with a layout-based rule.
What about list literals? items = new-keyword-here "red" "blue" "green" Again, I don't see how that can work out without introducing a keyword. Maybe reusing "data" would work: items = data "red" "blue" "green" :) Tillmann

Tillmann Rendel wrote:
I like to put commas at the beginning of lines, because there, I can make them line up and it is visually clear that they are all at the same nesting level. I like how the commas look a bit like bullet points. For example, I would write:
items = [ "red" , "blue" , "green" ]
Could we extend Garett's proposal to also allow prefixing the first element of a list with a comma, to support this style:
items = [ , "red" , "blue" , "green" ]
Allowing an optional extra comma both at the beginning and at the end would allow programmers the choice where they want to put their commas.
This is the style I am using for records and lists as well. Here an example from actual code data EventNetwork = EventNetwork { actuate :: IO () , pause :: IO () } These days, all my record definitions look like that. Allowing a superfluous leading comma would be great, because that makes it easier to move around the first line. Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com
participants (12)
-
Bardur Arantsson
-
Ben Millwood
-
Edward Kmett
-
Garrett Mitchener
-
Greg Weber
-
Heinrich Apfelmus
-
Ian Lynagh
-
Ian Lynagh
-
Johan Tibell
-
Roman Cheplyaka
-
Simon Marlow
-
Tillmann Rendel