Fix scoped type variables for expression type signatures
[ghc-hetmet.git] / compiler / hsSyn / HsDecls.lhs
index 54075d4..2128ad3 100644 (file)
@@ -39,16 +39,14 @@ import HsPat                ( HsConDetails(..), hsConArgs )
 import HsImpExp                ( pprHsVar )
 import HsTypes
 import NameSet          ( NameSet )
-import HscTypes                ( DeprecTxt )
 import CoreSyn         ( RuleName )
-import Kind            ( Kind, pprKind )
-import BasicTypes      ( Activation(..) )
+import {- Kind parts of -} Type                ( Kind, pprKind )
+import BasicTypes      ( Activation(..), DeprecTxt )
 import ForeignCall     ( CCallTarget(..), DNCallSpec, CCallConv, Safety,
                          CExportSpec(..), CLabelString ) 
 
 -- others:
-import FunDeps         ( pprFundeps )
-import Class           ( FunDep )
+import Class           ( FunDep, pprFundeps )
 import Outputable      
 import Util            ( count )
 import SrcLoc          ( Located(..), unLoc, noLoc )
@@ -451,7 +449,10 @@ isKindSigDecl (TyData     {tcdKindSig = Just _,
 isKindSigDecl other                              = False
 
 -- definition of an instance of an indexed type
-isIdxTyDecl = isJust . tcdTyPats
+isIdxTyDecl tydecl
+   | isTEqnDecl tydecl = True
+   | isDataDecl tydecl = isJust (tcdTyPats tydecl)
+   | otherwise        = False
 \end{code}
 
 Dealing with names
@@ -467,9 +468,7 @@ tyClDeclNames :: Eq name => TyClDecl name -> [Located name]
 -- We use the equality to filter out duplicate field names
 
 tyClDeclNames (TyFunction  {tcdLName = name})    = [name]
-tyClDeclNames (TySynonym   {tcdLName = name,
-                           tcdTyPats= Nothing}) = [name]
-tyClDeclNames (TySynonym   {}                  ) = []     -- type equation
+tyClDeclNames (TySynonym   {tcdLName = name})    = [name]
 tyClDeclNames (ForeignType {tcdLName = name})    = [name]
 
 tyClDeclNames (ClassDecl {tcdLName = cls_name, tcdSigs = sigs, tcdATs = ats})
@@ -518,19 +517,23 @@ instance OutputableBndr name
        dcolon <+> pprKind kind
         where
          typeMaybeIso = if iso 
-                        then ptext SLIT("type iso") 
-                        else ptext SLIT("type")
+                        then ptext SLIT("type family iso") 
+                        else ptext SLIT("type family")
 
     ppr (TySynonym {tcdLName = ltycon, tcdTyVars = tyvars, tcdTyPats = typats,
                    tcdSynRhs = mono_ty})
-      = hang (ptext SLIT("type") <+> pp_decl_head [] ltycon tyvars typats <+> 
+      = hang (ptext SLIT("type") <+> 
+             (if isJust typats then ptext SLIT("instance") else empty) <+>
+             pp_decl_head [] ltycon tyvars typats <+> 
              equals)
             4 (ppr mono_ty)
 
     ppr (TyData {tcdND = new_or_data, tcdCtxt = context, tcdLName = ltycon,
                 tcdTyVars = tyvars, tcdTyPats = typats, tcdKindSig = mb_sig, 
                 tcdCons = condecls, tcdDerivs = derivings})
-      = pp_tydecl (ppr new_or_data <+> 
+      = pp_tydecl (null condecls && isJust mb_sig) 
+                  (ppr new_or_data <+> 
+                  (if isJust typats then ptext SLIT("instance") else empty) <+>
                   pp_decl_head (unLoc context) ltycon tyvars typats <+> 
                   ppr_sig mb_sig)
                  (pp_condecls condecls)
@@ -574,12 +577,14 @@ pp_condecls cs@(L _ ConDecl{ con_res = ResTyGADT _ } : _) -- In GADT syntax
 pp_condecls cs                           -- In H98 syntax
   = equals <+> sep (punctuate (ptext SLIT(" |")) (map ppr cs))
 
-pp_tydecl pp_head pp_decl_rhs derivings
+pp_tydecl True pp_head pp_decl_rhs derivings
+  = pp_head
+pp_tydecl False pp_head pp_decl_rhs derivings
   = hang pp_head 4 (sep [
-       pp_decl_rhs,
-       case derivings of
-         Nothing          -> empty
-         Just ds          -> hsep [ptext SLIT("deriving"), parens (interpp'SP ds)]
+      pp_decl_rhs,
+      case derivings of
+        Nothing -> empty
+       Just ds -> hsep [ptext SLIT("deriving"), parens (interpp'SP ds)]
     ])
 
 instance Outputable NewOrData where