Wanted: warning option for usages of unary minus

Twan van Laarhoven twanvl at gmail.com
Thu May 17 12:40:04 EDT 2007


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)

Just an idea.

Twan


More information about the Haskell-prime mailing list