Commit 316e8cba authored by Simon Peyton Jones's avatar Simon Peyton Jones

Document -XTypeOperators, which had escaped documentation altogether thus far

parent 0cb60cee
......@@ -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>
......
......@@ -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>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment