proposal for trailing comma and semicolon

Garrett Mitchener garrett.mitchener at
Fri May 17 18:17:17 CEST 2013

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 = [

and it's pretty clear that the reason for this is that it's easier to
comment out the last item by prefixing --

items = [
  -- ,"green"

instead of

items = [
  "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 = [
  -- "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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Haskell-prime mailing list