Refactor (again) the handling of default methods
[ghc-hetmet.git] / compiler / types / Class.lhs
index 051bef1..27ec5c1 100644 (file)
@@ -10,14 +10,14 @@ module Class (
        Class, ClassOpItem, 
        DefMeth (..),
 
-       FunDep, pprFundeps,
+       FunDep, pprFundeps, pprFunDep,
 
        mkClass, classTyVars, classArity,
        classKey, className, classATs, classSelIds, classTyCon, classMethods,
        classBigSig, classExtraBigSig, classTvsFds, classSCTheta
     ) where
 
-#include "HsVersions.h"
+#include "Typeable.h"
 
 import {-# SOURCE #-} TyCon    ( TyCon )
 import {-# SOURCE #-} TypeRep  ( PredType )
@@ -26,7 +26,11 @@ import Var
 import Name
 import BasicTypes
 import Unique
+import Util
 import Outputable
+import FastString
+
+import qualified Data.Data as Data
 \end{code}
 
 %************************************************************************
@@ -67,7 +71,7 @@ type ClassOpItem = (Id, DefMeth)
        -- Default-method info
 
 data DefMeth = NoDefMeth               -- No default method
-            | DefMeth                  -- A polymorphic default method
+            | DefMeth Name             -- A polymorphic default method
             | GenDefMeth               -- A generic default method
              deriving Eq  
 \end{code}
@@ -169,15 +173,24 @@ instance Show Class where
     showsPrec p c = showsPrecSDoc p (ppr c)
 
 instance Outputable DefMeth where
-    ppr DefMeth     =  text "{- has default method -}"
-    ppr GenDefMeth  =  text "{- has generic method -}"
+    ppr (DefMeth n) =  ptext (sLit "Default method") <+> ppr n
+    ppr GenDefMeth  =  ptext (sLit "Generic default method")
     ppr NoDefMeth   =  empty   -- No default method
 
 pprFundeps :: Outputable a => [FunDep a] -> SDoc
 pprFundeps []  = empty
-pprFundeps fds = hsep (ptext SLIT("|") : punctuate comma (map ppr_fd fds))
-              where
-                ppr_fd (us, vs) = hsep [interppSP us, ptext SLIT("->"), 
-                                        interppSP vs]
+pprFundeps fds = hsep (ptext (sLit "|") : punctuate comma (map pprFunDep fds))
+
+pprFunDep :: Outputable a => FunDep a -> SDoc
+pprFunDep (us, vs) = hsep [interppSP us, ptext (sLit "->"), interppSP vs]
+
+instance Data.Typeable Class where
+    typeOf _ = Data.mkTyConApp (Data.mkTyCon "Class") []
+
+instance Data.Data Class where
+    -- don't traverse?
+    toConstr _   = abstractConstr "Class"
+    gunfold _ _  = error "gunfold"
+    dataTypeOf _ = mkNoRepType "Class"
 \end{code}