[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
Showing
- ghc/compiler/DEPEND-NOTES 3 additions, 3 deletionsghc/compiler/DEPEND-NOTES
- ghc/compiler/basicTypes/BasicTypes.lhs 38 additions, 1 deletionghc/compiler/basicTypes/BasicTypes.lhs
- ghc/compiler/basicTypes/DataCon.lhs 1 addition, 1 deletionghc/compiler/basicTypes/DataCon.lhs
- ghc/compiler/basicTypes/Id.lhs 33 additions, 8 deletionsghc/compiler/basicTypes/Id.lhs
- ghc/compiler/basicTypes/MkId.lhs 8 additions, 8 deletionsghc/compiler/basicTypes/MkId.lhs
- ghc/compiler/basicTypes/Name.lhs 12 additions, 9 deletionsghc/compiler/basicTypes/Name.lhs
- ghc/compiler/basicTypes/NameSet.lhs 3 additions, 1 deletionghc/compiler/basicTypes/NameSet.lhs
- ghc/compiler/basicTypes/OccName.lhs 3 additions, 1 deletionghc/compiler/basicTypes/OccName.lhs
- ghc/compiler/basicTypes/Unique.lhs 7 additions, 2 deletionsghc/compiler/basicTypes/Unique.lhs
- ghc/compiler/codeGen/CgExpr.lhs 3 additions, 2 deletionsghc/compiler/codeGen/CgExpr.lhs
- ghc/compiler/codeGen/CgTailCall.lhs 3 additions, 2 deletionsghc/compiler/codeGen/CgTailCall.lhs
- ghc/compiler/deSugar/MatchCon.lhs 1 addition, 1 deletionghc/compiler/deSugar/MatchCon.lhs
- ghc/compiler/hsSyn/HsBinds.lhs 13 additions, 7 deletionsghc/compiler/hsSyn/HsBinds.lhs
- ghc/compiler/hsSyn/HsDecls.lhs 42 additions, 22 deletionsghc/compiler/hsSyn/HsDecls.lhs
- ghc/compiler/hsSyn/HsExpr.lhs 5 additions, 0 deletionsghc/compiler/hsSyn/HsExpr.lhs
- ghc/compiler/hsSyn/HsMatches.lhs 8 additions, 6 deletionsghc/compiler/hsSyn/HsMatches.lhs
- ghc/compiler/hsSyn/HsPat.lhs 17 additions, 1 deletionghc/compiler/hsSyn/HsPat.lhs
- ghc/compiler/hsSyn/HsSyn.lhs 22 additions, 15 deletionsghc/compiler/hsSyn/HsSyn.lhs
- ghc/compiler/hsSyn/HsTypes.lhs 12 additions, 2 deletionsghc/compiler/hsSyn/HsTypes.lhs
- ghc/compiler/main/CmdLineOpts.lhs 2 additions, 5 deletionsghc/compiler/main/CmdLineOpts.lhs
Loading
Please register or sign in to comment