[project @ 2005-07-21 11:05:26 by simonpj]
authorsimonpj <unknown>
Thu, 21 Jul 2005 11:05:27 +0000 (11:05 +0000)
committersimonpj <unknown>
Thu, 21 Jul 2005 11:05:27 +0000 (11:05 +0000)
Arrange that a 'deriving' clause works for a GADT-syntax
data type delaration, provided it declares a Haskell-98-style
data type (i.e. no existentials or GADT stuff).

This just allows you to use a different syntax for data type
declarations without losing 'deriving'. A couple of people requested
this, and it's really easy to do.

ghc/compiler/parser/Parser.y.pp
ghc/compiler/typecheck/TcDeriv.lhs
ghc/docs/users_guide/glasgow_exts.xml

index 3de3793..67c7a59 100644 (file)
@@ -460,9 +460,11 @@ tycl_decl :: { LTyClDecl RdrName }
                                        -- in case constrs and deriving are both empty
                    (mkTyData DataType $2 Nothing (reverse (unLoc $3)) (unLoc $4)) }
 
-        | 'data' tycl_hdr opt_kind_sig 'where' gadt_constrlist -- No deriving for GADTs
+        | 'data' tycl_hdr opt_kind_sig 
+                'where' gadt_constrlist        -- No deriving for GADTs
+                deriving
                { L (comb4 $1 $2 $4 $5)
-                   (mkTyData DataType $2 $3 (reverse (unLoc $5)) Nothing) }
+                   (mkTyData DataType $2 $3 (reverse (unLoc $5)) (unLoc $6)) }
 
        | 'newtype' tycl_hdr '=' newconstr deriving
                { L (comb3 $1 $4 $5)
index c7526a4..326580b 100644 (file)
@@ -625,7 +625,7 @@ cond_std (gla_exts, tycon)
   where
     data_cons       = tyConDataCons tycon
     no_cons_why            = quotes (ppr tycon) <+> ptext SLIT("has no data constructors")
-    existential_why = quotes (ppr tycon) <+> ptext SLIT("has existentially-quantified constructor(s)")
+    existential_why = quotes (ppr tycon) <+> ptext SLIT("has non-Haskell-98 constructor(s)")
   
 cond_isEnumeration :: Condition
 cond_isEnumeration (gla_exts, tycon)
index 09ad8ca..a1c44ba 100644 (file)
@@ -3473,9 +3473,10 @@ type above, the type of each constructor must end with <literal> ... -> Term ...
 </para></listitem>
 
 <listitem><para>
-You cannot use a <literal>deriving</literal> clause on a GADT-style data type declaration,
-nor can you use record syntax.  (It's not clear what these constructs would mean.  For example,
-the record selectors might ill-typed.)  However, you can use strictness annotations, in the obvious places
+You cannot use record syntax on a GADT-style data type declaration.  (
+It's not clear what these it would mean.  For example,
+the record selectors might ill-typed.)
+However, you can use strictness annotations, in the obvious places
 in the constructor type:
 <programlisting>
   data Term a where
@@ -3486,6 +3487,23 @@ in the constructor type:
 </para></listitem>
 
 <listitem><para>
+You can use a <literal>deriving</literal> clause on a GADT-style data type
+declaration, but only if the data type could also have been declared in
+Haskell-98 syntax.   For example, these two declarations are equivalent
+<programlisting>
+  data Maybe1 a where {
+      Nothing1 :: Maybe a ;
+      Just1    :: a -> Maybe a
+    } deriving( Eq, Ord )
+
+  data Maybe2 a = Nothing2 | Just2 a 
+       deriving( Eq, Ord )
+</programlisting>
+This simply allows you to declare a vanilla Haskell-98 data type using the
+<literal>where</literal> form without losing the <literal>deriving</literal> clause.
+</para></listitem>
+
+<listitem><para>
 Pattern matching causes type refinement.  For example, in the right hand side of the equation
 <programlisting>
   eval :: Term a -> a