List syntax (was: Re: help from the community?)
Atze Dijkstra
atze at xs4all.nl
Fri Feb 2 11:47:23 EST 2007
On 2 Feb, 2007, at 16:55 , Malcolm Wallace wrote:
> Douglas Philips <dgou at mac.com> 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 believe that ghc at one time did accept any sequence of white-space
> separated commas as if they were a single comma, leading to code
> such as
> [ 1 , , 2 , 3 , ]
>
> Whilst programmers might be able to see the "obvious" meaning when it
> occurs in list exprs, do stmts, imports, exports, and the like, they
> might run into difficulties in the tuple case. For instance,
> (1,2,)
> has been proposed as syntactic sugar for a tuple-section, meaning
> \x-> (1,2,x)
> and this would be a perfectly reasonable and intuitive interpretation
> IMO. The number of commas is a powerful visual indication of the
> arity
> of the tuple.
This would be an instance of an arbitrary expression where a
subexpression has been omitted, forming a hole. So
[ 1 , , 2 , 3 , ] means \x y -> [ 1 , x , 2 , 3 , y ]
5 + * 6 means \x -> 5 + x * 6
(3 + *) means \x y -> (3 + x * y) (operator section)
Thus the following interpretations could be chosen from:
1 - an operator/comma without operand is an error (as a safety net
against typos)
2 - a comma without operand is redundant, means the same as an
expression without
3 - an operator/comma without operand has meaning as described above
I do prefer option 1, I do not mind writing \x -> 5 + x * 6
explicitly instead of implicitly (and more cryptic) 5 + * 6. I do not
feel that stretching the syntax in this way warrants the loss in
possibilities to check for errors.
regards,
- Atze -
Atze Dijkstra, Department of Information and Computing Sciences. /|\
Utrecht University, PO Box 80089, 3508 TB Utrecht, Netherlands. / | \
Tel.: +31-30-2534093/1454 | WWW : http://www.cs.uu.nl/~atze . /--| \
Fax : +31-30-2513971 .... | Email: atze at cs.uu.nl ............ / |___\
More information about the Haskell-prime
mailing list