From: simonpj Date: Thu, 21 Jul 2005 11:05:27 +0000 (+0000) Subject: [project @ 2005-07-21 11:05:26 by simonpj] X-Git-Tag: Initial_conversion_from_CVS_complete~338 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=5973d067b3f8e43d7dd336a634f31ab61a1a133f;p=ghc-hetmet.git [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. --- diff --git a/ghc/compiler/parser/Parser.y.pp b/ghc/compiler/parser/Parser.y.pp index 3de3793..67c7a59 100644 --- a/ghc/compiler/parser/Parser.y.pp +++ b/ghc/compiler/parser/Parser.y.pp @@ -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) diff --git a/ghc/compiler/typecheck/TcDeriv.lhs b/ghc/compiler/typecheck/TcDeriv.lhs index c7526a4..326580b 100644 --- a/ghc/compiler/typecheck/TcDeriv.lhs +++ b/ghc/compiler/typecheck/TcDeriv.lhs @@ -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) diff --git a/ghc/docs/users_guide/glasgow_exts.xml b/ghc/docs/users_guide/glasgow_exts.xml index 09ad8ca..a1c44ba 100644 --- a/ghc/docs/users_guide/glasgow_exts.xml +++ b/ghc/docs/users_guide/glasgow_exts.xml @@ -3473,9 +3473,10 @@ type above, the type of each constructor must end with ... -> Term ... -You cannot use a deriving 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: data Term a where @@ -3486,6 +3487,23 @@ in the constructor type: +You can use a deriving 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 + + data Maybe1 a where { + Nothing1 :: Maybe a ; + Just1 :: a -> Maybe a + } deriving( Eq, Ord ) + + data Maybe2 a = Nothing2 | Just2 a + deriving( Eq, Ord ) + +This simply allows you to declare a vanilla Haskell-98 data type using the +where form without losing the deriving clause. + + + Pattern matching causes type refinement. For example, in the right hand side of the equation eval :: Term a -> a