[commit: ghc] ghc-8.0: users_guide: small improvements on pattern synonyms. (86d63d6)

git at git.haskell.org git at git.haskell.org
Thu Mar 24 22:24:08 UTC 2016


Repository : ssh://git@git.haskell.org/ghc

On branch  : ghc-8.0
Link       : http://ghc.haskell.org/trac/ghc/changeset/86d63d610cad79d2600dbab44447445afb36795e/ghc

>---------------------------------------------------------------

commit 86d63d610cad79d2600dbab44447445afb36795e
Author: Dominik Bollmann <bollmann at seas.upenn.edu>
Date:   Thu Mar 24 22:32:56 2016 +0100

    users_guide: small improvements on pattern synonyms.
    
    Since the order of required and provided constraint contexts of pattern
    synonyms has been switched recently, I updated a couple places in the
    users guide's pattern synonym section to accommodate for this.
    
    Test Plan: read it :-)
    
    Reviewers: goldfire, thomie, mpickering, simonpj, austin, bgamari
    
    Reviewed By: bgamari
    
    Differential Revision: https://phabricator.haskell.org/D2034
    
    (cherry picked from commit 173a5d8ee4d3d8b7ddd2e8b81c957d03441c4f2b)


>---------------------------------------------------------------

86d63d610cad79d2600dbab44447445afb36795e
 docs/users_guide/glasgow_exts.rst | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/docs/users_guide/glasgow_exts.rst b/docs/users_guide/glasgow_exts.rst
index c05db45..603ab95 100644
--- a/docs/users_guide/glasgow_exts.rst
+++ b/docs/users_guide/glasgow_exts.rst
@@ -4011,9 +4011,8 @@ Pattern synonyms
     Allow the definition of pattern synonyms.
 
 Pattern synonyms are enabled by the flag :ghc-flag:`-XPatternSynonyms`, which is
-required for defining them, but *not* for using them. More information
-and examples of view patterns can be found on the
-`Wiki page <PatternSynonyms>`.
+required for defining them, but *not* for using them. More information and
+examples of view patterns can be found on the `Wiki page <PatternSynonyms>`.
 
 Pattern synonyms enable giving names to parametrized pattern schemes.
 They can also be thought of as abstract constructors that don't have a
@@ -4280,21 +4279,21 @@ it is assigned a *pattern type* of the form ::
 
       pattern P :: CReq => CProv => t1 -> t2 -> ... -> tN -> t
 
-where ⟨CProv⟩ and ⟨CReq⟩ are type contexts, and ⟨t1⟩, ⟨t2⟩, ..., ⟨tN⟩
+where ⟨CReq⟩ and ⟨CProv⟩ are type contexts, and ⟨t1⟩, ⟨t2⟩, ..., ⟨tN⟩
 and ⟨t⟩ are types. Notice the unusual form of the type, with two
-contexts ⟨CProv⟩ and ⟨CReq⟩:
+contexts ⟨CReq⟩ and ⟨CProv⟩:
+
+-  ⟨CReq⟩ are the constraints *required* to match the pattern.
 
 -  ⟨CProv⟩ are the constraints *made available (provided)* by a
    successful pattern match.
 
--  ⟨CReq⟩ are the constraints *required* to match the pattern.
-
 For example, consider ::
 
     data T a where
       MkT :: (Show b) => a -> b -> T a
 
-    f1 :: (Eq a, Num a) => T a -> String
+    f1 :: (Num a, Eq a) => T a -> String
     f1 (MkT 42 x) = show x
 
     pattern ExNumPat :: (Num a, Eq a) => (Show b) => b -> T a
@@ -4317,8 +4316,13 @@ Exactly the same reasoning applies to ``ExNumPat``: matching against
 
 Note also the following points
 
--  In the common case where ``Prov`` is empty, ``()``, it can be omitted
-   altogether.
+-  In the common case where ``CProv`` is empty, (i.e., ``()``), it can be
+   omitted altogether in the above pattern type signature for ``P``.
+
+-  However, if ``CProv`` is non-empty, while ``CReq`` is, the above pattern type
+   signature for ``P`` must be specified as ::
+
+     P :: () => CProv => t1 -> t2 -> .. -> tN -> t
 
 -  You may specify an explicit *pattern signature*, as we did for
    ``ExNumPat`` above, to specify the type of a pattern, just as you can
@@ -4379,7 +4383,7 @@ Note also the following points
    then be rejected.
 
    In short, if you want GADT-like behaviour for pattern synonyms, then
-   (unlike unlike concrete data constructors like ``S1``) you must write
+   (unlike concrete data constructors like ``S1``) you must write
    its type with explicit provided equalities. For a concrete data
    constructor like ``S1`` you can write its type signature as either
    ``S1 :: Bool -> S Bool`` or ``S1 :: (b~Bool) => Bool -> S b``; the



More information about the ghc-commits mailing list