diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2013-06-25 09:59:42 +0100 |
---|---|---|
committer | Simon Peyton Jones <simonpj@microsoft.com> | 2013-06-25 11:58:01 +0100 |
commit | 316e8cba29ac25dccb054e9b73e2d174b7b4b61a (patch) | |
tree | 97355643a575bf7a6996b84062898f2298d47226 | |
parent | 0cb60cee510ac65b06d9c5b1b3ea8bc9984f6f33 (diff) | |
download | haskell-316e8cba29ac25dccb054e9b73e2d174b7b4b61a.tar.gz |
Document -XTypeOperators, which had escaped documentation altogether thus far
-rw-r--r-- | docs/users_guide/flags.xml | 2 | ||||
-rw-r--r-- | docs/users_guide/glasgow_exts.xml | 58 |
2 files changed, 55 insertions, 5 deletions
diff --git a/docs/users_guide/flags.xml b/docs/users_guide/flags.xml index 6b8b17c3f6..a7b98391b2 100644 --- a/docs/users_guide/flags.xml +++ b/docs/users_guide/flags.xml @@ -1015,7 +1015,7 @@ </row> <row> <entry><option>-XTypeOperators</option></entry> - <entry>Enable type operators.</entry> + <entry>Enable <link linkend="type-operators">type operators</link>.</entry> <entry>dynamic</entry> <entry><option>-XNoTypeOperators</option></entry> </row> diff --git a/docs/users_guide/glasgow_exts.xml b/docs/users_guide/glasgow_exts.xml index b3985978be..0c4c890ada 100644 --- a/docs/users_guide/glasgow_exts.xml +++ b/docs/users_guide/glasgow_exts.xml @@ -2284,10 +2284,10 @@ to be written infix, very much like expressions. More specifically: </para></listitem> <listitem><para> Types, and class constraints, can be written infix. For example - <screen> - x :: Int :*: Bool - f :: (a :=: b) => a -> b - </screen> +<screen> + x :: Int :*: Bool + f :: (a :=: b) => a -> b +</screen> </para></listitem> <listitem><para> Back-quotes work @@ -2313,6 +2313,56 @@ to be written infix, very much like expressions. More specifically: </para> </sect2> +<sect2 id="type-operators"> +<title>Type operators</title> +<para> +In types, an operator symbol like <literal>(+)</literal> is normally treated as a type +<emphasis>variable</emphasis>, just like <literal>a</literal>. Thus in Haskell 98 you can say +<programlisting> +type T (+) = ((+), (+)) +-- Just like: type T a = (a,a) + +f :: T Int -> Int +f (x,y)= x +</programlisting> +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. +</para> +<para> +The language <option>-XTypeOperators</option> changes this behaviour: +<itemizedlist> +<listitem><para> +Operator symbols become type <emphasis>constructors</emphasis> rather than +type <emphasis>variables</emphasis>. +</para></listitem> +<listitem><para> +Operator symbols in types can be written infix, both in definitions and uses. +for example: +<programlisting> +data a + b = Plus a b +type Foo = Int + Bool +</programlisting> +</para></listitem> +<listitem><para> +There is now some potential ambiguity in import and export lists; for example +if you write <literal>import M( (+) )</literal> do you mean the +<emphasis>function</emphasis> <literal>(+)</literal> or the +<emphasis>type constructor</emphasis> <literal>(+)</literal>? +The default is the former, but GHC allows you to specify the latter +by preceding it with the keyword <literal>type</literal>, thus: +<programlisting> +import M( type (+) ) +</programlisting> +</para></listitem> +<listitem><para> +The fixity of a type operator may be set using the usual fixity declarations +but, as in <xref linkend="infix-tycons"/>, the function and type constructor share +a single fixity. +</para></listitem> +</itemizedlist> +</para> +</sect2> + <sect2 id="type-synonyms"> <title>Liberalised type synonyms</title> |