Commit 5973d067 authored by simonpj's avatar simonpj

[project @ 2005-07-21 11:05:26 by simonpj]

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.
parent a28ce054
......@@ -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)
......
......@@ -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)
......
......@@ -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
......@@ -3485,6 +3486,23 @@ in the constructor type:
</programlisting>
</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>
......
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