X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=docs%2Fusers_guide%2Fglasgow_exts.xml;h=c0feb5bff0f803e9588f011dd7a60ae4615b46eb;hp=43e84394c085b4b308f3bf210fdbb589d81dba87;hb=aecccd3eae278f4bcc9fc89c9250f889a66d5ded;hpb=cab2a4c125b422d675aa5ba086e3f94e97e9f81b
diff --git a/docs/users_guide/glasgow_exts.xml b/docs/users_guide/glasgow_exts.xml
index 43e8439..c0feb5b 100644
--- a/docs/users_guide/glasgow_exts.xml
+++ b/docs/users_guide/glasgow_exts.xml
@@ -2729,16 +2729,22 @@ GHC now allows stand-alone deriving declarations, enabled by
The syntax is identical to that of an ordinary instance declaration apart from (a) the keyword
deriving, and (b) the absence of the where part.
-You must supply a context (in the example the context is (Eq a)),
+Note the following points:
+
+
+You must supply an explicit context (in the example the context is (Eq a)),
exactly as you would in an ordinary instance declaration.
-(In contrast the context is inferred in a deriving clause
-attached to a data type declaration.)
+(In contrast, in a deriving clause
+attached to a data type declaration, the context is inferred.)
+
+
A deriving instance declaration
must obey the same rules concerning form and termination as ordinary instance declarations,
controlled by the same flags; see .
-
-
+
+
+
Unlike a deriving
declaration attached to a data declaration, the instance can be more specific
than the data type (assuming you also use
@@ -2752,8 +2758,31 @@ for example
This will generate a derived instance for (Foo [a]) and (Foo (Maybe a)),
but other types such as (Foo (Int,Bool)) will not be an instance of Eq.
+
+
+
+Unlike a deriving
+declaration attached to a data 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.)
+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:
+
+ data T a where
+ T1 :: T Int
+ T2 :: T Bool
+
+ deriving instance Show (T a)
+
+In this example, you cannot say ... deriving( Show ) on the
+data type declaration for T,
+because T is a GADT, but you can generate
+the instance declaration using stand-alone deriving.
+
+
The stand-alone syntax is generalised for newtypes in exactly the same
way that ordinary deriving clauses are generalised ().
For example:
@@ -2764,7 +2793,8 @@ For example:
GHC always treats the last parameter of the instance
(Foo in this example) as the type whose instance is being derived.
-
+
+