[Git][ghc/ghc][wip/T19064] Correct documentation around -XTypeOperators

Richard Eisenberg gitlab at gitlab.haskell.org
Wed Dec 16 20:00:33 UTC 2020



Richard Eisenberg pushed to branch wip/T19064 at Glasgow Haskell Compiler / GHC


Commits:
ae4f003b by Richard Eisenberg at 2020-12-16T15:00:20-05:00
Correct documentation around -XTypeOperators

Close #19064

- - - - -


1 changed file:

- docs/users_guide/exts/type_operators.rst


Changes:

=====================================
docs/users_guide/exts/type_operators.rst
=====================================
@@ -12,24 +12,11 @@ Type operators
 
     Allow the use and definition of types with operator names.
 
-In types, an operator symbol like ``(+)`` is normally treated as a type
-*variable*, just like ``a``. Thus in Haskell 98 you can say
+The language :extension:`TypeOperators` allows you to use infix operators
+in types.
 
-::
-
-    type T (+) = ((+), (+))
-    -- Just like: type T a = (a,a)
-
-    f :: T Int -> Int
-    f (x,y)= x
-
-As you can see, using operators in this way is not very useful, and
-Haskell 98 does not even allow you to write them infix.
-
-The language :extension:`TypeOperators` changes this behaviour:
-
--  Operator symbols become type *constructors* rather than type
-   *variables*.
+-  Operator symbols are *constructors* rather than type
+   *variables* (as they are in terms).
 
 -  Operator symbols in types can be written infix, both in definitions
    and uses. For example: ::
@@ -37,6 +24,12 @@ The language :extension:`TypeOperators` changes this behaviour:
        data a + b = Plus a b
        type Foo = Int + Bool
 
+-  Alphanumeric type constructors can now be written infix, using backquote
+   syntax::
+
+     x :: Int `Either` Bool
+     x = Left 5
+       
 -  There is now some potential ambiguity in import and export lists; for
    example if you write ``import M( (+) )`` do you mean the *function*
    ``(+)`` or the *type constructor* ``(+)``? The default is the former,
@@ -52,4 +45,18 @@ The language :extension:`TypeOperators` changes this behaviour:
    declarations but, as in :ref:`infix-tycons`, the function and type
    constructor share a single fixity.
 
-
+-  There is now potential ambiguity in the traditional syntax for
+   data constructor declarations. For example::
+
+     type a :+: b = Either a b
+     data X = Int :+: Bool :+: Char
+
+   This code wants to declare both a type-level ``:+:`` and a term-level
+   ``:+:`` (which is, generally, allowed). But we cannot tell how to
+   parenthesize the data constructor declaration in ``X``: either way
+   makes sense. We might
+   imagine that a fixity declaration could help us, but it is awkward
+   to apply the fixity declaration to the very definition of a new
+   data constructor. Instead of declaring delicate rules around this
+   issue, GHC simply rejects if the top level of a traditional-syntax
+   data constructor declaration uses two operators without parenthesizing.



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ae4f003bf1971be216b87dbfebde29ac531217c2

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ae4f003bf1971be216b87dbfebde29ac531217c2
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/20201216/bdba207f/attachment-0001.html>


More information about the ghc-commits mailing list