Wanted: warning option for usages of unary minus

Iavor Diatchki iavor.diatchki at gmail.com
Mon May 14 13:48:35 EDT 2007


Hello,

I agree with Simon on this one: "x-1" should parse as expected (i.e.,
the infix operator "-" applied to two arguments "x" and "1"). Having
this result in a type error would be confusing to both beginners and
working Haskell programmers.

I think that if we want to change anything at all, we should simply
eliminate the unary negation operator without changing the lexer
(i.e., we would have only positive literals).  Then we would have to
be explicit about what is currently happening implicitly in
Haskell98---we would write "negate 1" instead of "-1".

However, I don't thinks that this change is justified---as far as I
can see, the only benefit is that it simplifies the parser.  However,
the change is not backward compatible and may break some programs.

-Iavor

On 5/14/07, Simon Marlow <simonmarhaskell at gmail.com> wrote:
> John Meacham wrote:
> > On Wed, Apr 11, 2007 at 09:05:21AM +0100, Simon Marlow wrote:
> >> I definitely think that -1# should be parsed as a single lexeme.
> >> Presumably it was easier at the time to do it the way it is, I don't
> >> remember exactly.
> >>
> >> I'd support a warning for use of prefix negation, or alternatively you
> >> could implement the Haskell' proposal to remove prefix negation completely
> >> - treat the unary minus as part of a numeric literal in the lexer only.
> >> This would have to be optional for now, so that we can continue to support
> >> Haskell 98 of course.
> >
> > yes please! odd that I look forward to such a minor change in the big
> > scheme of things, but the current treatment of negation has annoyed me
> > more than any other misfeature I think.
>
> 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" (syntax in which whitespace matters should be avoided like the plague,
> IMO).  I think this would be worse than the current situation.
>
> Cheers,
>         Simon
>
>
> _______________________________________________
> Haskell-prime mailing list
> Haskell-prime at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-prime
>


More information about the Glasgow-haskell-users mailing list