diff options
author | Vladislav Zavialov <vlad.z.4096@gmail.com> | 2020-07-01 22:56:15 +0300 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-07-27 07:06:56 -0400 |
commit | aee45d9ea8c6cf4ebad4d5c732748923c7865cbe (patch) | |
tree | 3cb1952015aeacdc886ba142f23c97f9b29acae7 /docs | |
parent | 52685cf7c077c51e3719e3c4dd5ca8257a99c4ea (diff) | |
download | haskell-aee45d9ea8c6cf4ebad4d5c732748923c7865cbe.tar.gz |
Improve NegativeLiterals (#18022, 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'.
This also applies to unboxed literals, e.g. -1#.
See GHC Proposal #229 for the definition of a closing token.
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.
Diffstat (limited to 'docs')
-rw-r--r-- | docs/users_guide/8.12.1-notes.rst | 7 | ||||
-rw-r--r-- | docs/users_guide/exts/negative_literals.rst | 14 |
2 files changed, 15 insertions, 6 deletions
diff --git a/docs/users_guide/8.12.1-notes.rst b/docs/users_guide/8.12.1-notes.rst index dd429c22d4..ea198f5167 100644 --- a/docs/users_guide/8.12.1-notes.rst +++ b/docs/users_guide/8.12.1-notes.rst @@ -224,6 +224,13 @@ Language f = (- x) -- operator section c = (-x) -- negation +* The behavior of :extension:`NegativeLiterals` changed, and now we require + that a negative literal must not be preceded by a closing token (see + `GHC Proposal #229 <https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0229-whitespace-bang-patterns.rst>`__ + for the definition of a closing token). In other words, we parse ``f -123`` + as ``f (-123)``, but ``x-123`` as ``(-) x 123``. Before this amendment, + :extension:`NegativeLiterals` caused ``x-123`` to be parsed as ``x(-123)``. + Compiler ~~~~~~~~ diff --git a/docs/users_guide/exts/negative_literals.rst b/docs/users_guide/exts/negative_literals.rst index 237fabf044..c2dbc1eff4 100644 --- a/docs/users_guide/exts/negative_literals.rst +++ b/docs/users_guide/exts/negative_literals.rst @@ -24,9 +24,11 @@ will elicit an unexpected integer-literal-overflow message. Whitespace can be inserted, as in ``- 123``, to force interpretation as two tokens. -One pitfall is that with :extension:`NegativeLiterals`, ``x-1`` will -be parsed as ``x`` applied to the argument ``-1``, which is usually -not what you want. ``x - 1`` or even ``x- 1`` can be used instead -for subtraction. To avoid this, consider using :extension:`LexicalNegation` -instead. - +In 8.12, the behavior of this extension changed, and now we require that a negative literal must not be preceded by a closing token (see +`GHC Proposal #229 <https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0229-whitespace-bang-patterns.rst>`__ +for the definition of a closing token). In other words, we parse ``f -123`` as ``f (-123)``, but ``x-123`` as ``(-) x +123``. Before this amendment, :extension:`NegativeLiterals` caused ``x-123`` to be parsed as ``x(-123)``. + +:extension:`NegativeLiterals` is a subset of :extension:`LexicalNegation`. That +is, enabling both of those extensions has the same effect as enabling +:extension:`LexicalNegation` alone. |