summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2014-03-10 11:08:37 +0000
committerSimon Peyton Jones <simonpj@microsoft.com>2014-03-10 11:11:29 +0000
commit9d14262299fe721e49eb0efadebca9d095c834b3 (patch)
treea35d95ed21ace2ee47f6c6a327b6e72c762fa4b0 /docs
parentd246c62afd7312185aee9433b065ea99e4fa4054 (diff)
downloadhaskell-9d14262299fe721e49eb0efadebca9d095c834b3.tar.gz
Improve documentation of standalone deriving (c.f. Trac #8851)
Diffstat (limited to 'docs')
-rw-r--r--docs/users_guide/glasgow_exts.xml28
1 files changed, 21 insertions, 7 deletions
diff --git a/docs/users_guide/glasgow_exts.xml b/docs/users_guide/glasgow_exts.xml
index dc1fbb5a9c..4217b7dc41 100644
--- a/docs/users_guide/glasgow_exts.xml
+++ b/docs/users_guide/glasgow_exts.xml
@@ -3752,8 +3752,16 @@ GHC now allows stand-alone <literal>deriving</literal> declarations, enabled by
</programlisting>
The syntax is identical to that of an ordinary instance declaration apart from (a) the keyword
<literal>deriving</literal>, and (b) the absence of the <literal>where</literal> part.
-Note the following points:
+</para>
+<para>
+However, standalone deriving differs from a <literal>deriving</literal> clause in a number
+of important ways:
<itemizedlist>
+<listitem><para>The standalone deriving declaration does not need to be in the
+same module as the data type declaration. (But be aware of the dangers of
+orphan instances (<xref linkend="orphan-modules"/>).
+</para></listitem>
+
<listitem><para>
You must supply an explicit context (in the example the context is <literal>(Eq a)</literal>),
exactly as you would in an ordinary instance declaration.
@@ -3762,12 +3770,6 @@ attached to a data type declaration, the context is inferred.)
</para></listitem>
<listitem><para>
-A <literal>deriving instance</literal> declaration
-must obey the same rules concerning form and termination as ordinary instance declarations,
-controlled by the same flags; see <xref linkend="instance-decls"/>.
-</para></listitem>
-
-<listitem><para>
Unlike a <literal>deriving</literal>
declaration attached to a <literal>data</literal> declaration, the instance can be more specific
than the data type (assuming you also use
@@ -3789,6 +3791,8 @@ declaration attached to a <literal>data</literal> declaration,
GHC does not restrict the form of the data type. Instead, GHC simply generates the appropriate
boilerplate code for the specified class, and typechecks it. If there is a type error, it is
your problem. (GHC will show you the offending code if it has a type error.)
+</para>
+<para>
The merit of this is that you can derive instances for GADTs and other exotic
data types, providing only that the boilerplate code does indeed typecheck. For example:
<programlisting>
@@ -3811,6 +3815,16 @@ the side-conditions are necessarily more conservative, but any error message
may be more comprehensible.
</para>
</listitem>
+</itemizedlist></para>
+
+<para>
+In other ways, however, a standalone deriving obeys the same rules as ordinary deriving:
+<itemizedlist>
+<listitem><para>
+A <literal>deriving instance</literal> declaration
+must obey the same rules concerning form and termination as ordinary instance declarations,
+controlled by the same flags; see <xref linkend="instance-decls"/>.
+</para></listitem>
<listitem>
<para>The stand-alone syntax is generalised for newtypes in exactly the same