summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorVladislav Zavialov <vlad.z.4096@gmail.com>2019-10-30 08:44:34 +0300
committerVladislav Zavialov <vlad.z.4096@gmail.com>2019-11-27 11:32:18 +0300
commit8168b42a95ddf37c56958955eef065eb8747470f (patch)
treea677a67987372dac9732ea67f6ab37a77c02641a /docs
parent5a08f7d405bbedfdc20c07f64726899f594e9d07 (diff)
downloadhaskell-8168b42a95ddf37c56958955eef065eb8747470f.tar.gz
Whitespace-sensitive bang patterns (#1087, #17162)wip/whitespace-and-lookahead
This patch implements a part of GHC Proposal #229 that covers five operators: * the bang operator (!) * the tilde operator (~) * the at operator (@) * the dollar operator ($) * the double dollar operator ($$) Based on surrounding whitespace, these operators are disambiguated into bang patterns, lazy patterns, strictness annotations, type applications, splices, and typed splices. This patch doesn't cover the (-) operator or the -Woperator-whitespace warning, which are left as future work.
Diffstat (limited to 'docs')
-rw-r--r--docs/users_guide/bugs.rst39
-rw-r--r--docs/users_guide/glasgow_exts.rst34
-rw-r--r--docs/users_guide/using-warnings.rst7
3 files changed, 60 insertions, 20 deletions
diff --git a/docs/users_guide/bugs.rst b/docs/users_guide/bugs.rst
index c0cffa0ee8..4dc49f0328 100644
--- a/docs/users_guide/bugs.rst
+++ b/docs/users_guide/bugs.rst
@@ -49,6 +49,45 @@ Lexical syntax
reserving ``forall`` as a keyword has significance. For instance, GHC will
not parse the type signature ``foo :: forall x``.
+- The ``(!)`` operator, when written in prefix form (preceded by whitespace
+ and not followed by whitespace, as in ``f !x = ...``), is interpreted as a
+ bang pattern, contrary to the Haskell Report, which prescribes to treat ``!``
+ as an operator regardless of surrounding whitespace. Note that this does not
+ imply that GHC always enables :extension:`BangPatterns`. Without the
+ extension, GHC will issue a parse error on ``f !x``, asking to enable the
+ extension.
+
+- Irrefutable patterns must be written in prefix form::
+
+ f ~a ~b = ... -- accepted by both GHC and the Haskell Report
+ f ~ a ~ b = ... -- accepted by the Haskell Report but not GHC
+
+ When written in non-prefix form, ``(~)`` is treated by GHC as a regular
+ infix operator.
+
+ See `GHC Proposal #229 <https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0229-whitespace-bang-patterns.rst>`__
+ for the precise rules.
+
+- Strictness annotations in data declarations must be written in prefix form::
+
+ data T = MkT !Int -- accepted by both GHC and the Haskell Report
+ data T = MkT ! Int -- accepted by the Haskell Report but not GHC
+
+ See `GHC Proposal #229 <https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0229-whitespace-bang-patterns.rst>`__
+ for the precise rules.
+
+- As-patterns must not be surrounded by whitespace::
+
+ f p@(x, y, z) = ... -- accepted by both GHC and the Haskell Report
+ f p @ (x, y, z) = ... -- accepted by the Haskell Report but not GHC
+
+ When surrounded by whitespace, ``(@)`` is treated by GHC as a regular infix
+ operator.
+
+ See `GHC Proposal #229 <https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0229-whitespace-bang-patterns.rst>`__
+ for the precise rules.
+
+
.. _infelicities-syntax:
Context-free syntax
diff --git a/docs/users_guide/glasgow_exts.rst b/docs/users_guide/glasgow_exts.rst
index af3d48e0a3..d23681e0b3 100644
--- a/docs/users_guide/glasgow_exts.rst
+++ b/docs/users_guide/glasgow_exts.rst
@@ -13108,10 +13108,9 @@ enable the quotation subset of Template Haskell (i.e. without splice syntax).
The :extension:`TemplateHaskellQuotes` extension is considered safe under
:ref:`safe-haskell` while :extension:`TemplateHaskell` is not.
-- A splice is written ``$x``, where ``x`` is an identifier, or
- ``$(...)``, where the "..." is an arbitrary expression. There must be
- no space between the "$" and the identifier or parenthesis. This use
- of "$" overrides its meaning as an infix operator, just as "M.x"
+- A splice is written ``$x``, where ``x`` is an arbitrary expression.
+ There must be no space between the "$" and the expression.
+ This use of "$" overrides its meaning as an infix operator, just as "M.x"
overrides the meaning of "." as an infix operator. If you want the
infix operator, put spaces around it.
@@ -13147,9 +13146,8 @@ The :extension:`TemplateHaskellQuotes` extension is considered safe under
See :ref:`pts-where` for using partial type signatures in quotations.
-- A *typed* expression splice is written ``$$x``, where ``x`` is an
- identifier, or ``$$(...)``, where the "..." is an arbitrary
- expression.
+- A *typed* expression splice is written ``$$x``, where ``x`` is
+ is an arbitrary expression.
A typed expression splice can occur in place of an expression; the
spliced expression must have type ``Q (TExp a)``
@@ -14323,12 +14321,15 @@ Note the following points:
f !x = 3
- Is this a definition of the infix function "``(!)``", or of the "``f``"
- with a bang pattern? GHC resolves this ambiguity in favour of the
- latter. If you want to define ``(!)`` with bang-patterns enabled, you
- have to do so using prefix notation: ::
+ Is this a definition of the infix function "``(!)``", or of the "``f``" with
+ a bang pattern? GHC resolves this ambiguity by looking at the surrounding
+ whitespace: ::
- (!) f x = 3
+ a ! b = ... -- infix operator
+ a !b = ... -- bang pattern
+
+ See `GHC Proposal #229 <https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0229-whitespace-bang-patterns.rst>`__
+ for the precise rules.
.. _strict-data:
@@ -14359,6 +14360,13 @@ we interpret it as if they had written ::
The extension only affects definitions in this module.
+The ``~`` annotation must be written in prefix form::
+
+ data T = MkT ~Int -- valid
+ data T = MkT ~ Int -- invalid
+
+See `GHC Proposal #229 <https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0229-whitespace-bang-patterns.rst>`__
+for the precise rules.
.. _strict:
@@ -14393,7 +14401,7 @@ optionally had by adding ``!`` in front of a variable.
Adding ``~`` in front of ``x`` gives the regular lazy behavior.
- Turning patterns into irrefutable ones requires ``~(~p)`` or ``(~ ~p)`` when ``Strict`` is enabled.
+ Turning patterns into irrefutable ones requires ``~(~p)`` when ``Strict`` is enabled.
diff --git a/docs/users_guide/using-warnings.rst b/docs/users_guide/using-warnings.rst
index 62b644aa8a..4649f86de0 100644
--- a/docs/users_guide/using-warnings.rst
+++ b/docs/users_guide/using-warnings.rst
@@ -46,7 +46,6 @@ generally likely to indicate bugs in your program. These are:
* :ghc-flag:`-Winaccessible-code`
* :ghc-flag:`-Wstar-is-type`
* :ghc-flag:`-Wstar-binder`
- * :ghc-flag:`-Wspace-after-bang`
The following flags are simple ways to select standard "packages" of warnings:
@@ -1280,12 +1279,6 @@ of ``-W(no-)*``.
per-module basis with :ghc-flag:`-Wno-simplifiable-class-constraints
<-Wsimplifiable-class-constraints>`.
-.. ghc-flag:: -Wspace-after-bang
- :shortdesc: warn for missing space before the second argument
- of an infix definition of ``(!)`` when
- :extension:`BangPatterns` are not enabled
- :type: dynamic
- :reverse: -Wno-missing-space-after-bang
.. ghc-flag:: -Wtabs
:shortdesc: warn if there are tabs in the source file
:type: dynamic