List syntax (was: Re: help from the community?)
Douglas Philips
dgou at mac.com
Fri Feb 2 12:05:36 EST 2007
On 2007 Feb 2, at 11:32 AM, Brian Hulley wrote:
> Douglas Philips wrote:
>> What would be the proper way to propose that:
>>> ( exp1 , ... , expk ) (tuple, k>=2)
>>> [ exp1 , ... , expk ] (list, k>=1)
>> be amended to:
>>> ( exp1 , ... , expk [ , ] ) (tuple, k>=2)
>>> [ exp1 , ... , expk [ , ] ] (list, k>=1)
>
> I think a problem with the above proposal is that by allowing an
> optional trailing comma the compiler can no longer detect as an
> error the case where the programmer has simply just forgotten to
> fill in the last element of the tuple/list. The existing syntax
> forces the user to do some extra work fiddling about with commas
> but the reward is that the compiler can verify that you haven't
> forgotten the last argument.
I assert that the trailing comma is a feature, not a programmer
forgetting "the last element", and that this
is already explicitly allowed, as per the syntax fragments already
quoted, repeated here for convenience:
-- from: http://www.haskell.org/onlinereport/syntax-iso.html#sectB.4
impspec -> ( import1 , ... , importn [ , ] ) (n>=0)
| hiding ( import1 , ... , importn [ , ] ) (n>=0)
exports -> ( export1 , ... , exportn [ , ] ) (n>=0)
stmts -> stmt1 ... stmtn exp [ ; ] (n>=0)
stmt -> exp ;
| pat <- exp ;
| let decls ;
| ; (empty statement)
(Personally I prefer no separators at all as per your other
suggestion, but haven't fully grok'd that yet, but either way, the
"overall" syntax should be consistent, so saying "a trailing comma
means you forgot the last
element" should imply removing the trailing commas above, right? Or,
perhaps, it means saying that, as Python and Ruby and .. programmers
have been able to do, the regularity of ( <expr> ',' )* is compelling
for eye/brain pattern matching and other silly human factors
reasons. :-) )
--Doug
More information about the Haskell-prime
mailing list