- = FunTyCon -- Kind = Type -> Type -> Type
-
- | DataTyCon Unique{-TyConKey-}
- Name
- Kind
- [TyVar]
- [(Class,Type)] -- Its context
- [Id] -- Its data constructors, with fully polymorphic types
- [Class] -- Classes which have derived instances
- NewOrData
-
- | TupleTyCon Unique -- cached
- Name -- again, we could do without this, but
- -- it makes life somewhat easier
- Arity -- just a special case of DataTyCon
- -- Kind = BoxedTypeKind
- -- -> ... (n times) ...
- -- -> BoxedTypeKind
- -- -> BoxedTypeKind
-
- | PrimTyCon -- Primitive types; cannot be defined in Haskell
- Unique -- Always unboxed; hence never represented by a closure
- Name -- Often represented by a bit-pattern for the thing
- Kind -- itself (eg Int#), but sometimes by a pointer to
-
- | SpecTyCon -- A specialised TyCon; eg (Arr# Int#), or (List Int#)
- TyCon
- [Maybe Type] -- Specialising types
-
- -- OLD STUFF ABOUT Array types. Use SpecTyCon instead
- -- ([PrimRep] -> PrimRep) -- a heap-allocated object (eg ArrInt#).
- -- The primitive types Arr# and StablePtr# have
- -- parameters (hence arity /= 0); but the rest don't.
- -- Only arrays use the list in a non-trivial way.
- -- Length of that list must == arity.
-
- | SynTyCon
- Unique
- Name
- Kind
- Arity
- [TyVar] -- Argument type variables
- Type -- Right-hand side, mentioning these type vars.
- -- Acts as a template for the expansion when
- -- the tycon is applied to some types.
-
-data NewOrData
- = NewType -- "newtype Blah ..."
- | DataType -- "data Blah ..."
+ = FunTyCon {
+ tyConUnique :: Unique,
+ tyConName :: Name,
+ tyConKind :: Kind,
+ tyConArity :: Arity
+ }
+
+
+ | AlgTyCon { -- Tuples, data type, and newtype decls.
+ -- All lifted, all boxed
+ tyConUnique :: Unique,
+ tyConName :: Name,
+ tyConKind :: Kind,
+ tyConArity :: Arity,
+
+ tyConTyVars :: [TyVar],
+ tyConArgVrcs :: ArgVrcs,
+ algTyConTheta :: [(Class,[Type])],
+
+ dataCons :: [DataCon],
+ -- Its data constructors, with fully polymorphic types
+ -- This list can be empty, when we import a data type abstractly,
+ -- either (a) the interface is hand-written and doesn't give
+ -- the constructors, or
+ -- (b) in a quest for fast compilation we don't import
+ -- the constructors
+
+ algTyConDerivings :: [Class], -- Classes which have derived instances
+
+ algTyConFlavour :: AlgTyConFlavour,
+ algTyConRec :: RecFlag, -- Tells whether the data type is part of
+ -- a mutually-recursive group or not
+
+ algTyConClass_maybe :: Maybe Class -- Nothing for ordinary types;
+ -- Just c for the type constructor
+ -- for dictionaries of class c.
+
+ }
+
+ | PrimTyCon { -- Primitive types; cannot be defined in Haskell
+ -- NB: All of these guys are *unlifted*, but not all are *unboxed*
+ tyConUnique :: Unique,
+ tyConName :: Name,
+ tyConKind :: Kind,
+ tyConArity :: Arity,
+ tyConArgVrcs :: ArgVrcs,
+ primTyConRep :: PrimRep
+ }
+
+ | TupleTyCon {
+
+ tyConUnique :: Unique,
+ tyConName :: Name,
+ tyConKind :: Kind,
+ tyConArity :: Arity,
+ tyConBoxed :: Bool, -- True for boxed; False for unboxed
+ tyConTyVars :: [TyVar],
+ dataCon :: DataCon
+ }
+
+ | SynTyCon {
+ tyConUnique :: Unique,
+ tyConName :: Name,
+ tyConKind :: Kind,
+ tyConArity :: Arity,
+
+ tyConTyVars :: [TyVar], -- Bound tyvars
+ synTyConDefn :: Type, -- Right-hand side, mentioning these type vars.
+ -- Acts as a template for the expansion when
+ -- the tycon is applied to some types.
+ tyConArgVrcs :: ArgVrcs
+ }
+
+ | KindCon { -- Type constructor at the kind level
+ tyConUnique :: Unique,
+ tyConName :: Name,
+ tyConKind :: SuperKind,
+ tyConArity :: Arity
+ }
+
+ | SuperKindCon { -- The type of kind variables or boxity variables,
+ tyConUnique :: Unique,
+ tyConName :: Name
+ }
+
+type ArgVrcs = [(Bool,Bool)] -- Tyvar variance info: [(occPos,occNeg)]
+ -- *NB*: this is tyvar variance info, *not*
+ -- termvar usage info.
+
+data AlgTyConFlavour
+ = DataTyCon -- Data type
+ | EnumTyCon -- Special sort of enumeration type
+ | NewTyCon Type -- Newtype, with its *ultimate* representation type
+ -- By 'ultimate' I mean that the rep type is not itself
+ -- a newtype or type synonym.
+
+ -- The rep type has explicit for-alls for the tyvars of
+ -- the TyCon. Thus:
+ -- newtype T a = MkT [(a,Int)]
+ -- The rep type is forall a. [(a,Int)]
+ --
+ -- The rep type isn't entirely simple:
+ -- for a recursive newtype we pick () as the rep type
+ -- newtype T = MkT T