Wanted: warning option for usages of unary minus

Isaac Dupree isaacdupree at charter.net
Thu May 17 13:44:01 EDT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Twan van Laarhoven wrote:
> 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.

Indeed, and in some language syntax designs it would certainly be a good
system for prefix operators.

Existing parsers may have some difficulty. How about
> {-comment-}-1
?
how about
> WeirdNumber{value=2,weird=True}-1
?

Although likely to make any actual code work, it seems a bit complicated
from the mindset of current Haskell parsing/lexing.

"(b) not followed by whitespace." can be replaced by
(b) followed by a digit
if desired not to allow it for negating arbitrary expressions.


Isaac
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGTJRgHgcxvIWYTTURAqpMAJ9rpCFwzOG/ZSF0qpM/hD/mFKrQ1wCfSRCK
2nKiBzRs/8thmgrdBT+SowA=
=lFCl
-----END PGP SIGNATURE-----


More information about the Glasgow-haskell-users mailing list