Big tidy-up of deriving code
[ghc-hetmet.git] / compiler / hsSyn / HsDecls.lhs
index 733a8ea..6d49bd8 100644 (file)
@@ -1,7 +1,9 @@
 %
+% (c) The University of Glasgow 2006
 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
 %
-\section[HsDecls]{Abstract syntax: global declarations}
+
+HsDecls: Abstract syntax: global declarations
 
 Definitions for: @TyDecl@ and @oCnDecl@, @ClassDecl@,
 @InstDecl@, @DefaultDecl@ and @ForeignDecl@.
@@ -33,27 +35,25 @@ module HsDecls (
 import {-# SOURCE #-}  HsExpr( HsExpr, pprExpr )
        -- Because Expr imports Decls via HsBracket
 
-import HsBinds         ( HsValBinds(..), HsBind, LHsBinds, plusHsValBinds,
-                         Sig(..), LSig, LFixitySig, pprLHsBinds,
-                         emptyValBindsIn, emptyValBindsOut )
-import HsPat           ( HsConDetails(..), hsConArgs, HsRecField(..) )
-import HsImpExp                ( pprHsVar )
+import HsBinds
+import HsPat
+import HsImpExp
 import HsTypes
-import HsDoc           ( HsDoc, LHsDoc, ppr_mbDoc )
-import NameSet          ( NameSet )
-import CoreSyn         ( RuleName )
-import {- Kind parts of -} Type                ( Kind, pprKind )
-import BasicTypes      ( Activation(..), DeprecTxt )
-import ForeignCall     ( CCallTarget(..), DNCallSpec, CCallConv, Safety,
-                         CExportSpec(..), CLabelString ) 
+import HsDoc
+import NameSet
+import CoreSyn
+import {- Kind parts of -} Type
+import BasicTypes
+import ForeignCall
 
 -- others:
-import Class           ( FunDep, pprFundeps )
+import Class
 import Outputable      
-import Util            ( count )
-import SrcLoc          ( Located(..), unLoc, noLoc )
+import Util
+import SrcLoc
 import FastString
-import Maybe            ( isJust )
+
+import Data.Maybe       ( isJust )
 \end{code}
 
 %************************************************************************
@@ -344,11 +344,6 @@ Interface file code:
 
 
 \begin{code}
--- TyClDecls are precisely the kind of declarations that can 
--- appear in interface files; or (internally) in GHC's interface
--- for a module.  That's why (despite the misnomer) IfaceSig and ForeignType
--- are both in TyClDecl
-
 -- Representation of indexed types
 -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 -- Kind signatures of indexed types come in two flavours:
@@ -386,12 +381,20 @@ data TyClDecl name
   | TyData {   tcdND     :: NewOrData,
                tcdCtxt   :: LHsContext name,           -- Context
                tcdLName  :: Located name,              -- Type constructor
+
                tcdTyVars :: [LHsTyVarBndr name],       -- Type variables
+                       
                tcdTyPats :: Maybe [LHsType name],      -- Type patterns
-               tcdKindSig:: Maybe Kind,                -- Optional kind sig; 
-                                                       -- (only for the 
-                                                       -- 'where' form and
-                                                       -- indexed type sigs)
+                       -- Just [t1..tn] for data instance T t1..tn = ...
+                       --      in this case tcdTyVars = fv( tcdTyPats )
+                       -- Nothing for everything else
+
+               tcdKindSig:: Maybe Kind,                -- Optional kind sig 
+                       -- (Just k) for 
+                       --      (a) GADT-style data type decls with user kind sig
+                       --      (b) 'data instance' decls with user kind sig    
+                       --      (c) 'data family' decls, whether or not there is a kind sig
+                       --              (this is how we distinguish a data family decl)
 
                tcdCons   :: [LConDecl name],           -- Data constructors
                        -- For data T a = T1 | T2 a          the LConDecls all have ResTyH98
@@ -405,6 +408,9 @@ data TyClDecl name
                        -- Typically the foralls and ty args are empty, but they
                        -- are non-empty for the newtype-deriving case
     }
+       -- data family:   tcdPats = Nothing, tcdCons = [], tcdKindSig = Just k
+       -- data instance: tcdPats = Just tys
+       -- data:          tcdPats = Nothing, tcdCons is non-empty
 
   | TyFunction {tcdLName  :: Located name,             -- type constructor
                tcdTyVars :: [LHsTyVarBndr name],       -- type variables
@@ -415,8 +421,9 @@ data TyClDecl name
   | TySynonym {        tcdLName  :: Located name,              -- type constructor
                tcdTyVars :: [LHsTyVarBndr name],       -- type variables
                tcdTyPats :: Maybe [LHsType name],      -- Type patterns
-                                                       -- 'Nothing' => vanilla
-                                                       --   type synonym
+                       -- See comments for tcdTyPats in TyData
+                       -- 'Nothing' => vanilla type synonym
+
                tcdSynRhs :: LHsType name               -- synonym expansion
     }
 
@@ -745,12 +752,11 @@ instDeclATs (InstDecl _ _ _ ats) = ats
 \begin{code}
 type LDerivDecl name = Located (DerivDecl name)
 
-data DerivDecl name
-  = DerivDecl (LHsType name) (Located name)
+data DerivDecl name = DerivDecl (LHsType name)
 
 instance (OutputableBndr name) => Outputable (DerivDecl name) where
-    ppr (DerivDecl ty n) 
-        = hsep [ptext SLIT("deriving"), ppr ty, ptext SLIT("for"), ppr n]
+    ppr (DerivDecl ty) 
+        = hsep [ptext SLIT("derived instance"), ppr ty]
 \end{code}
 
 %************************************************************************