Another round of External Core fixes
[ghc-hetmet.git] / compiler / hsSyn / HsDecls.lhs
index 4f0fc03..4be320f 100644 (file)
@@ -9,6 +9,13 @@ Definitions for: @TyDecl@ and @oCnDecl@, @ClassDecl@,
 @InstDecl@, @DefaultDecl@ and @ForeignDecl@.
 
 \begin{code}
+{-# OPTIONS -fno-warn-incomplete-patterns #-}
+-- The above warning supression flag is a temporary kludge.
+-- While working on this module you are encouraged to remove it and fix
+-- any warnings in the module. See
+--     http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
+-- for details
+
 module HsDecls (
        HsDecl(..), LHsDecl, TyClDecl(..), LTyClDecl, 
        InstDecl(..), LInstDecl, DerivDecl(..), LDerivDecl, NewOrData(..),
@@ -399,8 +406,10 @@ data TyClDecl name
                        -- instance' decl with explicit kind sig
 
                tcdCons   :: [LConDecl name],           -- Data constructors
-                       -- For data T a = T1 | T2 a          the LConDecls all have ResTyH98
-                       -- For data T a where { T1 :: T a }  the LConDecls all have ResTyGADT
+                       -- For data T a = T1 | T2 a          
+                        --   the LConDecls all have ResTyH98
+                       -- For data T a where { T1 :: T a }  
+                        --   the LConDecls all have ResTyGADT
 
                tcdDerivs :: Maybe [LHsType name]
                        -- Derivings; Nothing => not specified
@@ -427,9 +436,9 @@ data TyClDecl name
                tcdSigs    :: [LSig name],              -- Methods' signatures
                tcdMeths   :: LHsBinds name,            -- Default methods
                tcdATs     :: [LTyClDecl name],         -- Associated types; ie
-                                                       --   only 'TyData',
-                                                       --   'TyFunction',
-                                                       --   and 'TySynonym'
+                                                       --   only 'TyFamily' and
+                                                       --   'TySynonym'; the
+                                                        --   latter for defaults
                tcdDocs    :: [LDocDecl name]           -- Haddock docs
     }
 
@@ -463,7 +472,7 @@ isSynDecl _other                        = False
 
 -- type class
 isClassDecl (ClassDecl {}) = True
-isClassDecl other         = False
+isClassDecl _              = False
 
 -- type family declaration
 isFamilyDecl (TyFamily {}) = True
@@ -499,6 +508,7 @@ tyClDeclNames (ClassDecl {tcdLName = cls_name, tcdSigs = sigs, tcdATs = ats})
 tyClDeclNames (TyData {tcdLName = tc_name, tcdCons = cons})
   = tc_name : conDeclsNames (map unLoc cons)
 
+tyClDeclTyVars :: TyClDecl name -> [LHsTyVarBndr name]
 tyClDeclTyVars (TyFamily    {tcdTyVars = tvs}) = tvs
 tyClDeclTyVars (TySynonym   {tcdTyVars = tvs}) = tvs
 tyClDeclTyVars (TyData      {tcdTyVars = tvs}) = tvs
@@ -595,12 +605,14 @@ pp_decl_head context thing _      (Just typats) -- explicit type patterns
   = hsep [ pprHsContext context, ppr thing
         , hsep (map (pprParendHsType.unLoc) typats)]
 
+pp_condecls :: OutputableBndr name => [LConDecl name] -> SDoc
 pp_condecls cs@(L _ ConDecl{ con_res = ResTyGADT _ } : _) -- In GADT syntax
   = hang (ptext SLIT("where")) 2 (vcat (map ppr cs))
 pp_condecls cs                           -- In H98 syntax
   = equals <+> sep (punctuate (ptext SLIT(" |")) (map ppr cs))
 
-pp_tydecl True pp_head pp_decl_rhs derivings
+pp_tydecl :: OutputableBndr name => Bool -> SDoc -> SDoc -> Maybe [LHsType name] -> SDoc
+pp_tydecl True  pp_head _ _
   = pp_head
 pp_tydecl False pp_head pp_decl_rhs derivings
   = hang pp_head 4 (sep [
@@ -676,7 +688,7 @@ data ResType name
 \end{code}
 
 \begin{code}
-conDeclsNames :: forall name. Eq name => [ConDecl name] -> [Located name]
+conDeclsNames :: (Eq name) => [ConDecl name] -> [Located name]
   -- See tyClDeclNames for what this does
   -- The function is boringly complicated because of the records
   -- And since we only have equality, we have to be a little careful
@@ -715,6 +727,12 @@ pprConDecl (ConDecl con expl tvs cxt (PrefixCon arg_tys) (ResTyGADT res_ty) _)
 pprConDecl (ConDecl con expl tvs cxt (RecCon fields) (ResTyGADT res_ty) _)
   = sep [pprHsForAll expl tvs cxt, ppr con <+> ppr_fields fields <+> dcolon <+> ppr res_ty]
 
+pprConDecl (ConDecl con _expl _tvs _cxt (InfixCon _ _) (ResTyGADT _res_ty) _)
+  = pprPanic "pprConDecl" (ppr con)
+       -- In GADT syntax we don't allow infix constructors
+
+
+ppr_fields :: OutputableBndr name => [ConDeclField name] -> SDoc
 ppr_fields fields = braces (sep (punctuate comma (map ppr_fld fields)))
   where
     ppr_fld (ConDeclField { cd_fld_name = n, cd_fld_type = ty, 
@@ -743,10 +761,10 @@ data InstDecl name
 instance (OutputableBndr name) => Outputable (InstDecl name) where
 
     ppr (InstDecl inst_ty binds uprags ats)
-      = vcat [hsep [ptext SLIT("instance"), ppr inst_ty, ptext SLIT("where")],
-             nest 4 (ppr ats),
-             nest 4 (ppr uprags),
-             nest 4 (pprLHsBinds binds) ]
+      = vcat [hsep [ptext SLIT("instance"), ppr inst_ty, ptext SLIT("where")]
+             , nest 4 $ vcat (map ppr ats)
+            , nest 4 $ vcat (map ppr uprags)
+            , nest 4 $ pprLHsBinds binds ]
 
 -- Extract the declarations of associated types from an instance
 --
@@ -864,11 +882,11 @@ data FoType = DNType              -- In due course we'll add subtype stuff
 
 instance OutputableBndr name => Outputable (ForeignDecl name) where
   ppr (ForeignImport n ty fimport) =
-    ptext SLIT("foreign import") <+> ppr fimport <+> 
-    ppr n <+> dcolon <+> ppr ty
+    hang (ptext SLIT("foreign import") <+> ppr fimport <+> ppr n)
+       2 (dcolon <+> ppr ty)
   ppr (ForeignExport n ty fexport) =
-    ptext SLIT("foreign export") <+> ppr fexport <+> 
-    ppr n <+> dcolon <+> ppr ty
+    hang (ptext SLIT("foreign export") <+> ppr fexport <+> ppr n)
+       2 (dcolon <+> ppr ty)
 
 instance Outputable ForeignImport where
   ppr (DNImport                                spec) = 
@@ -883,7 +901,7 @@ instance Outputable ForeignImport where
       pprCEntity header lib (CFunction (StaticTarget lbl)) = 
         ptext SLIT("static") <+> ftext header <+> char '&' <>
        pprLib lib <> ppr lbl
-      pprCEntity header lib (CFunction (DynamicTarget)) = 
+      pprCEntity _      _   (CFunction (DynamicTarget)) =
         ptext SLIT("dynamic")
       pprCEntity _      _   (CWrapper) = ptext SLIT("wrapper")
       --
@@ -928,7 +946,7 @@ collectRuleBndrSigTys :: [RuleBndr name] -> [LHsType name]
 collectRuleBndrSigTys bndrs = [ty | RuleBndrSig _ ty <- bndrs]
 
 instance OutputableBndr name => Outputable (RuleDecl name) where
-  ppr (HsRule name act ns lhs fv_lhs rhs fv_rhs)
+  ppr (HsRule name act ns lhs _fv_lhs rhs _fv_rhs)
        = sep [text "{-# RULES" <+> doubleQuotes (ftext name) <+> ppr act,
               nest 4 (pp_forall <+> pprExpr (unLoc lhs)), 
               nest 4 (equals <+> pprExpr (unLoc rhs) <+> text "#-}") ]
@@ -961,6 +979,7 @@ data DocDecl name
 instance Outputable (DocDecl name) where
   ppr _ = text "<document comment>"
 
+docDeclDoc :: DocDecl name -> HsDoc name
 docDeclDoc (DocCommentNext d) = d
 docDeclDoc (DocCommentPrev d) = d
 docDeclDoc (DocCommentNamed _ d) = d