Improve NegativeLiterals (GHC Proposal #344)
Implementation of GHC Proposal #344.
Before this patch, NegativeLiterals
used to parse x-1
as x (-1)
. This may not be what the user expects, and now it is fixed: x-1
is parsed as (-) x 1
.
We achieve this by the following requirement:
- When lexing a negative literal, it must not be preceded by a 'closing token'. See GHC Proposal #229 for the definition of a closing token.
This also applies to unboxed literals, e.g. -1#
.
A nice consequence of this change is that -XNegativeLiterals
becomes a subset of -XLexicalNegation
. In other words, enabling both of those extensions has the same effect as enabling -XLexicalNegation
alone.