Wanted: warning option for usages of unary minus

John Meacham john at repetae.net
Fri May 18 20:24:14 EDT 2007


On Thu, May 17, 2007 at 06:40:04PM +0200, Twan van Laarhoven wrote:
> Simon Marlow wrote:
> >...
> >
> >Really?  I'm beginning to have second thoughts about the proposed change 
> >to negation for Haskell'.  The main reason, and this isn't pointed out 
> >as well as it should be on the wiki, is that "x-1" will cease to be an 
> >infix application of (-), it will parse as x applied to the literal 
> >(-1).  And this is different from "x - 1"
> 
> There is one other alternative for parsing:
>    "-" is a unary minus if and only if it is
>        a) preceded by whitespace or one of "[({;,", and
>        b) not followed by whitespace.
> 
> So:
>   x - 1     ==    (-) x 1
>   x-1       ==    (-) x 1
>   x -1      ==    x (negate 1)
>   x -(1)    ==    x (negate 1)
>   x (-1)    ==    x (negate 1)
>   x (- 1)   ==    x (\y -> y - 1)

also
(c) has a digit after it.

also note that a big point of this is that we can get rid of 'negate' in
the translation, so the literal 
-1 now desugars to

(fromInteger -1)

rather than the current

(negate (fromInteger 1))  

(which requires 2 dictionary lookups for a simple constant! sigh.

we also have the option of removing negate from the 'Num' class if so
desired.

        John

-- 
John Meacham - ⑆repetae.net⑆john⑈


More information about the Glasgow-haskell-users mailing list