[Git][ghc/ghc][master] Clarify pitfalls of NegativeLiterals; see #18022.
Marge Bot
gitlab at gitlab.haskell.org
Thu May 21 16:20:27 UTC 2020
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
d3d055b8 by Galen Huntington at 2020-05-21T12:20:18-04:00
Clarify pitfalls of NegativeLiterals; see #18022.
- - - - -
1 changed file:
- docs/users_guide/exts/negative_literals.rst
Changes:
=====================================
docs/users_guide/exts/negative_literals.rst
=====================================
@@ -8,16 +8,24 @@ Negative literals
:since: 7.8.1
- Enable the use of un-parenthesized negative numeric literals.
+ Enable negative numeric literals.
The literal ``-123`` is, according to Haskell98 and Haskell 2010,
+two tokens, a unary minus (``-``) and the number 123, and is
desugared as ``negate (fromInteger 123)``. The language extension
-:extension:`NegativeLiterals` means that it is instead desugared as
-``fromInteger (-123)``.
+:extension:`NegativeLiterals` causes it to be treated as a single
+token and desugared as ``fromInteger (-123)``.
-This can make a difference when the positive and negative range of a
-numeric data type don't match up. For example, in 8-bit arithmetic -128
-is representable, but +128 is not. So ``negate (fromInteger 128)`` will
-elicit an unexpected integer-literal-overflow message.
+This can be useful when the positive and negative range of a numeric
+data type don't match up. For example, in 8-bit arithmetic -128
+is representable, but +128 is not. So ``negate (fromInteger 128)``
+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.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d3d055b8d10a549e42d18ae4859bc902f939f534
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d3d055b8d10a549e42d18ae4859bc902f939f534
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20200521/088bc3a9/attachment-0001.html>
More information about the ghc-commits
mailing list