The @Class@ datatype
\begin{code}
-{-# OPTIONS_GHC -w #-}
--- 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/WorkingConventions#Warnings
--- for details
-
module Class (
Class, ClassOpItem,
DefMeth (..),
+ defMethSpecOfDefMeth,
- FunDep, pprFundeps,
+ FunDep, pprFundeps, pprFunDep,
mkClass, classTyVars, classArity,
- classKey, className, classATs, classSelIds, classTyCon, classMethods,
+ classKey, className, classATs, classSelIds, classTyCon, classMethods, classOpItems,
classBigSig, classExtraBigSig, classTvsFds, classSCTheta
) where
-#include "HsVersions.h"
+#include "Typeable.h"
import {-# SOURCE #-} TyCon ( TyCon )
import {-# SOURCE #-} TypeRep ( PredType )
import Name
import BasicTypes
import Unique
+import Util
import Outputable
+import FastString
+
+import qualified Data.Data as Data
\end{code}
%************************************************************************
-- 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
+
+-- | Convert a `DefMethSpec` to a `DefMeth`, which discards the name field in
+-- the `DefMeth` constructor of the `DefMeth`.
+defMethSpecOfDefMeth :: DefMeth -> DefMethSpec
+defMethSpecOfDefMeth meth
+ = case meth of
+ NoDefMeth -> NoDM
+ DefMeth _ -> VanillaDM
+ GenDefMeth -> GenericDM
+
\end{code}
The @mkClass@ function fills in the indirect superclasses.
classMethods (Class {classOpStuff = op_stuff})
= [op_sel | (op_sel, _) <- op_stuff]
+classOpItems :: Class -> [ClassOpItem]
+classOpItems (Class { classOpStuff = op_stuff})
+ = op_stuff
+
+classTvsFds :: Class -> ([TyVar], [FunDep TyVar])
classTvsFds c
= (classTyVars c, classFunDeps c)
+classBigSig :: Class -> ([TyVar], [PredType], [Id], [ClassOpItem])
classBigSig (Class {classTyVars = tyvars, classSCTheta = sc_theta,
classSCSels = sc_sels, classOpStuff = op_stuff})
= (tyvars, sc_theta, sc_sels, op_stuff)
+
+classExtraBigSig :: Class -> ([TyVar], [FunDep TyVar], [PredType], [Id], [TyCon], [ClassOpItem])
classExtraBigSig (Class {classTyVars = tyvars, classFunDeps = fundeps,
classSCTheta = sc_theta, classSCSels = sc_sels,
classATs = ats, classOpStuff = op_stuff})
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}