summaryrefslogtreecommitdiff
path: root/ghc/compiler/hsSyn/HsBinds.lhs
diff options
context:
space:
mode:
authorsimonpj <unknown>2000-10-03 08:43:05 +0000
committersimonpj <unknown>2000-10-03 08:43:05 +0000
commit710e207487929c4a5977b5ee3bc6e539091953db (patch)
treeb7426a2301bda799286128b3cdffdec90cc334f1 /ghc/compiler/hsSyn/HsBinds.lhs
parentaf099cc124dcb1c5cbb1166aed1177848540c3ab (diff)
downloadhaskell-710e207487929c4a5977b5ee3bc6e539091953db.tar.gz
[project @ 2000-10-03 08:43:00 by simonpj]
-------------------------------------- Adding generics SLPJ Oct 2000 -------------------------------------- This big commit adds Hinze/PJ-style generic class definitions, based on work by Andrei Serjantov. For example: class Bin a where toBin :: a -> [Int] fromBin :: [Int] -> (a, [Int]) toBin {| Unit |} Unit = [] toBin {| a :+: b |} (Inl x) = 0 : toBin x toBin {| a :+: b |} (Inr y) = 1 : toBin y toBin {| a :*: b |} (x :*: y) = toBin x ++ toBin y fromBin {| Unit |} bs = (Unit, bs) fromBin {| a :+: b |} (0:bs) = (Inl x, bs') where (x,bs') = fromBin bs fromBin {| a :+: b |} (1:bs) = (Inr y, bs') where (y,bs') = fromBin bs fromBin {| a :*: b |} bs = (x :*: y, bs'') where (x,bs' ) = fromBin bs (y,bs'') = fromBin bs' Now we can say simply instance Bin a => Bin [a] and the compiler will derive the appropriate code automatically. (About 9k lines of diffs. Ha!) Generic related things ~~~~~~~~~~~~~~~~~~~~~~ * basicTypes/BasicTypes: The EP type (embedding-projection pairs) * types/TyCon: An extra field in an algebraic tycon (genInfo) * types/Class, and hsSyn/HsBinds: Each class op (or ClassOpSig) carries information about whether it a) has no default method b) has a polymorphic default method c) has a generic default method There's a new data type for this: Class.DefMeth * types/Generics: A new module containing good chunk of the generic-related code It has a .hi-boot file (alas). * typecheck/TcInstDcls, typecheck/TcClassDcl: Most of the rest of the generics-related code * hsSyn/HsTypes: New infix type form to allow types of the form data a :+: b = Inl a | Inr b * parser/Parser.y, Lex.lhs, rename/ParseIface.y: Deal with the new syntax * prelude/TysPrim, TysWiredIn: Need to generate generic stuff for the wired-in TyCons * rename/RnSource RnBinds: A rather gruesome hack to deal with scoping of type variables from a generic patterns. Details commented in the ClassDecl case of RnSource.rnDecl. Of course, there are many minor renamer consequences of the other changes above. * lib/std/PrelBase.lhs Data type declarations for Unit, :+:, :*: Slightly unrelated housekeeping ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * hsSyn/HsDecls: ClassDecls now carry the Names for their implied declarations (superclass selectors, tycon, etc) in a list, rather than laid out one by one. This simplifies code between the parser and the type checker. * prelude/PrelNames, TysWiredIn: All the RdrNames are now together in PrelNames. * utils/ListSetOps: Add finite mappings based on equality and association lists (Assoc a b) Move stuff from List.lhs that is related
Diffstat (limited to 'ghc/compiler/hsSyn/HsBinds.lhs')
-rw-r--r--ghc/compiler/hsSyn/HsBinds.lhs20
1 files changed, 13 insertions, 7 deletions
diff --git a/ghc/compiler/hsSyn/HsBinds.lhs b/ghc/compiler/hsSyn/HsBinds.lhs
index 894a6321ab..b33ab92ba2 100644
--- a/ghc/compiler/hsSyn/HsBinds.lhs
+++ b/ghc/compiler/hsSyn/HsBinds.lhs
@@ -25,6 +25,7 @@ import BasicTypes ( RecFlag(..), Fixity )
import Outputable
import SrcLoc ( SrcLoc )
import Var ( TyVar )
+import Class ( DefMeth (..) )
\end{code}
%************************************************************************
@@ -236,11 +237,9 @@ data Sig name
(HsType name)
SrcLoc
- | ClassOpSig name -- Selector name
- (Maybe -- Nothing for source-file class signatures
- (name, -- Default-method name (if any)
- Bool)) -- True <=> there is an explicit, programmer-supplied
- -- default declaration in the class decl
+ | ClassOpSig name -- Selector name
+ (Maybe (DefMeth name)) -- Nothing for source-file class signatures
+ -- Gives DefMeth info for interface files sigs
(HsType name)
SrcLoc
@@ -338,8 +337,15 @@ ppr_sig (ClassOpSig var dm ty _)
= sep [ppr var <+> pp_dm <+> dcolon, nest 4 (ppr ty)]
where
pp_dm = case dm of
- Just (_, True) -> equals -- Default-method indicator
- other -> empty
+ Just (DefMeth _) -> equals -- Default method indicator
+ Just GenDefMeth -> semi -- Generic method indicator
+ Just NoDefMeth -> empty -- No Method at all
+ -- Not convinced this is right...
+ -- Not used in interface file output hopefully
+ -- but needed for ddump-rn ??
+ other -> dot
+ -- empty -- No method at all
+
ppr_sig (SpecSig var ty _)
= sep [ hsep [text "{-# SPECIALIZE", ppr var, dcolon],