Commit 3fc6ead1 authored by Simon Peyton Jones's avatar Simon Peyton Jones
Browse files

Tidy up documentation of generalisation

parent 37be6f06
...@@ -7181,8 +7181,24 @@ scope over the methods defined in the <literal>where</literal> part. For exampl ...@@ -7181,8 +7181,24 @@ scope over the methods defined in the <literal>where</literal> part. For exampl
</sect2> </sect2>
<sect2>
<title>Bindings and generalisation</title>
<sect3 id="monomorphism">
<title>Switching off the dreaded Monomorphism Restriction</title>
<indexterm><primary><option>-XNoMonomorphismRestriction</option></primary></indexterm>
<sect2 id="typing-binds"> <para>Haskell's monomorphism restriction (see
<ulink url="http://www.haskell.org/onlinereport/decls.html#sect4.5.5">Section
4.5.5</ulink>
of the Haskell Report)
can be completely switched off by
<option>-XNoMonomorphismRestriction</option>.
</para>
</sect3>
<sect3 id="typing-binds">
<title>Generalised typing of mutually recursive bindings</title> <title>Generalised typing of mutually recursive bindings</title>
<para> <para>
...@@ -7243,23 +7259,9 @@ pattern binding must have the same context. For example, this is fine: ...@@ -7243,23 +7259,9 @@ pattern binding must have the same context. For example, this is fine:
g y = (y &lt;= y) || f True g y = (y &lt;= y) || f True
</programlisting> </programlisting>
</para> </para>
</sect2> </sect3>
<sect2 id="monomorphism">
<title>Switching off the dreaded Monomorphism Restriction</title>
<indexterm><primary><option>-XNoMonomorphismRestriction</option></primary></indexterm>
<para>Haskell's monomorphism restriction (see
<ulink url="http://www.haskell.org/onlinereport/decls.html#sect4.5.5">Section
4.5.5</ulink>
of the Haskell Report)
can be completely switched off by
<option>-XNoMonomorphismRestriction</option>.
</para>
</sect2>
<sect2 id="mono-local-binds"> <sect3 id="mono-local-binds">
<title>Let-generalisation</title> <title>Let-generalisation</title>
<para> <para>
An ML-style language usually generalises the type of any let-bound or where-bound variable, An ML-style language usually generalises the type of any let-bound or where-bound variable,
...@@ -7288,11 +7290,13 @@ All of this applies only to bindings that lack an explicit type signature, so th ...@@ -7288,11 +7290,13 @@ All of this applies only to bindings that lack an explicit type signature, so th
infer its type. If you supply a type signature, then that fixes type of the binding, end of story. infer its type. If you supply a type signature, then that fixes type of the binding, end of story.
</para><para> </para><para>
The rationale for this more conservative strategy is given in The rationale for this more conservative strategy is given in
<ulink url="http://research.microsoft.com/~simonpj/papers/constraints/index.htm">the papers</ulink> "Let should not be generalised" and "Modular type inference with local assumptions". <ulink url="http://research.microsoft.com/~simonpj/papers/constraints/index.htm">the papers</ulink> "Let should not be generalised" and "Modular type inference with local assumptions", and
a related <ulink url="http://hackage.haskell.org/trac/ghc/blog/LetGeneralisationInGhc7">blog post</ulink>.
</para><para> </para><para>
The flag <option>-XMonoLocalBinds</option> is implied by <option>-XTypeFamilies</option> and <option>-XGADTs</option>. You can switch it off again The flag <option>-XMonoLocalBinds</option> is implied by <option>-XTypeFamilies</option> and <option>-XGADTs</option>. You can switch it off again
with <option>-XNoMonoLocalBinds</option> but type inference becomes less predicatable if you do so. (Read the papers!) with <option>-XNoMonoLocalBinds</option> but type inference becomes less predicatable if you do so. (Read the papers!)
</para> </para>
</sect3>
</sect2> </sect2>
<sect2 id="type-holes"> <sect2 id="type-holes">
......
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