~ patterns

Patryk Zadarnowski patrykz at cse.unsw.edu.au
Thu Feb 2 17:54:59 EST 2006

On 03/02/2006, at 9:25 AM, Wolfgang Jeltsch wrote:

> Am Mittwoch, 1. Februar 2006 01:32 schrieb Patryk Zadarnowski:
>> [...]
>> The proposal would be to remove the unary "-" altogether, and,  
>> instead,
>> extend the lexical syntax of numeric constant to allow "+" and "-"  
>> prefix.
> Would this mean that (-x) is a section while (-1) isn't?  That  
> would be
> confusing.
> Apart from this, I would like to see the only unary operator of  
> Haskell
> removed.

Yes, it *would* mean that (-x) and (- 1) are sections while (-1)  
isn't, and
yes, that would be slightly confusing (and a good compiler might want to
issue a warning whenever it sees a construct of the form (-identifier).

However, it is NOT more confusing than what we already have with
the (.) operator. Consider:

	(Just . not) is a perfectly reasonable function of type (Bool ->  
Maybe Bool)


	(Just.not) has a completely different meaning (and is probably  
illegal unless
	you have a module called "Just", which exports a function called  

In the case of the (.) operator, the confusion is more significant,  
since the meaning
is context-sensitive. With the proposed "-" operator, it would be  
purely lexical, and
therefore easy to warn about (if the compiler wishes to do so.)

In both cases, accidentally omitting a space will result in a  
compiler or type error
anyway, since (-x) has a different type than (- x), so such accidents  
will be picked
by the compiler rather than generating invalid code.

In summary: yes, the change would create *some* confusion. But much  
less confusion
than that caused by the current treatment of (-).


More information about the Haskell-prime mailing list