proposal for trailing comma and semicolon

2013-05-17 Thread Garrett Mitchener
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
___
Haskell-prime mailing list
Haskell-prime@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-prime


Re: proposal for trailing comma and semicolon

2013-05-17 Thread Johan Tibell
On Fri, May 17, 2013 at 9:17 AM, Garrett Mitchener <
garrett.mitche...@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
___
Haskell-prime mailing list
Haskell-prime@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-prime


Re: proposal for trailing comma and semicolon

2013-05-17 Thread Bardur Arantsson
On 05/17/2013 06:32 PM, Johan Tibell wrote:
> On Fri, May 17, 2013 at 9:17 AM, Garrett Mitchener <
> garrett.mitche...@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.



___
Haskell-prime mailing list
Haskell-prime@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-prime


Re: proposal for trailing comma and semicolon

2013-05-17 Thread Edward Kmett
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 wrote:

> On 05/17/2013 06:32 PM, Johan Tibell wrote:
> > On Fri, May 17, 2013 at 9:17 AM, Garrett Mitchener <
> > garrett.mitche...@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.
>
>
>
> ___
> 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


Re: proposal for trailing comma and semicolon

2013-05-17 Thread Tillmann Rendel

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-prime


Re: proposal for trailing comma and semicolon

2013-05-17 Thread Greg Weber
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 <
ren...@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-prime
>
___
Haskell-prime mailing list
Haskell-prime@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-prime


Re: proposal for trailing comma and semicolon

2013-05-17 Thread 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


Re: proposal for trailing comma and semicolon

2013-05-17 Thread 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


Re: proposal for trailing comma and semicolon

2013-05-17 Thread Roman Cheplyaka
I use them sometimes, but would do that much more if they didn't require
adding an extension.

Roman

* Edward Kmett  [2013-05-17 15:24:27-0400]
> 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


___
Haskell-prime mailing list
Haskell-prime@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-prime