[project @ 2000-10-03 08:43:00 by simonpj]
authorsimonpj <unknown>
Tue, 3 Oct 2000 08:43:05 +0000 (08:43 +0000)
committersimonpj <unknown>
Tue, 3 Oct 2000 08:43:05 +0000 (08:43 +0000)
commit710e207487929c4a5977b5ee3bc6e539091953db
treeb7426a2301bda799286128b3cdffdec90cc334f1
parentaf099cc124dcb1c5cbb1166aed1177848540c3ab
[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
66 files changed:
ghc/compiler/DEPEND-NOTES
ghc/compiler/basicTypes/BasicTypes.lhs
ghc/compiler/basicTypes/DataCon.lhs
ghc/compiler/basicTypes/Id.lhs
ghc/compiler/basicTypes/MkId.lhs
ghc/compiler/basicTypes/Name.lhs
ghc/compiler/basicTypes/NameSet.lhs
ghc/compiler/basicTypes/OccName.lhs
ghc/compiler/basicTypes/Unique.lhs
ghc/compiler/codeGen/CgExpr.lhs
ghc/compiler/codeGen/CgTailCall.lhs
ghc/compiler/deSugar/MatchCon.lhs
ghc/compiler/hsSyn/HsBinds.lhs
ghc/compiler/hsSyn/HsDecls.lhs
ghc/compiler/hsSyn/HsExpr.lhs
ghc/compiler/hsSyn/HsMatches.lhs
ghc/compiler/hsSyn/HsPat.lhs
ghc/compiler/hsSyn/HsSyn.lhs
ghc/compiler/hsSyn/HsTypes.lhs
ghc/compiler/main/CmdLineOpts.lhs
ghc/compiler/main/Main.lhs
ghc/compiler/main/MkIface.lhs
ghc/compiler/parser/Lex.lhs
ghc/compiler/parser/ParseUtil.lhs
ghc/compiler/parser/Parser.y
ghc/compiler/parser/RdrHsSyn.lhs
ghc/compiler/prelude/PrelInfo.lhs
ghc/compiler/prelude/PrelNames.lhs
ghc/compiler/prelude/TysPrim.lhs
ghc/compiler/prelude/TysWiredIn.lhs
ghc/compiler/profiling/SCCfinal.lhs
ghc/compiler/rename/ParseIface.y
ghc/compiler/rename/Rename.lhs
ghc/compiler/rename/RnBinds.lhs
ghc/compiler/rename/RnEnv.lhs
ghc/compiler/rename/RnExpr.lhs
ghc/compiler/rename/RnHsSyn.lhs
ghc/compiler/rename/RnIfaces.lhs
ghc/compiler/rename/RnMonad.lhs
ghc/compiler/rename/RnNames.lhs
ghc/compiler/rename/RnSource.lhs
ghc/compiler/typecheck/TcBinds.lhs
ghc/compiler/typecheck/TcClassDcl.lhs
ghc/compiler/typecheck/TcDeriv.lhs
ghc/compiler/typecheck/TcEnv.lhs
ghc/compiler/typecheck/TcInstDcls.lhs
ghc/compiler/typecheck/TcInstUtil.lhs
ghc/compiler/typecheck/TcMatches.lhs
ghc/compiler/typecheck/TcModule.lhs
ghc/compiler/typecheck/TcMonoType.lhs
ghc/compiler/typecheck/TcPat.lhs
ghc/compiler/typecheck/TcRules.lhs
ghc/compiler/typecheck/TcSimplify.lhs
ghc/compiler/typecheck/TcTyClsDecls.lhs
ghc/compiler/typecheck/TcTyDecls.lhs
ghc/compiler/typecheck/TcType.lhs
ghc/compiler/types/Class.lhs
ghc/compiler/types/Generics.hi-boot-5 [new file with mode: 0644]
ghc/compiler/types/Generics.lhs [new file with mode: 0644]
ghc/compiler/types/TyCon.lhs
ghc/compiler/types/Type.lhs
ghc/compiler/types/TypeRep.lhs
ghc/compiler/utils/ListSetOps.lhs
ghc/compiler/utils/Maybes.lhs
ghc/compiler/utils/Util.lhs
ghc/lib/std/PrelBase.lhs