-mkFunTyCon = FunTyCon
-mkSpecTyCon = SpecTyCon
-
-mkTupleTyCon arity
- = TupleTyCon u n arity
- where
- n = mkTupleTyConName arity
- u = uniqueOf n
-
-mkDataTyCon name
- = DataTyCon (nameUnique name) name
-mkPrimTyCon name
- = PrimTyCon (nameUnique name) name
-mkSynTyCon name
- = SynTyCon (nameUnique name) name
-
-isFunTyCon FunTyCon = True
-isFunTyCon _ = False
-
-isPrimTyCon (PrimTyCon _ _ _) = True
-isPrimTyCon _ = False
-
--- At present there are no unboxed non-primitive types, so
--- isBoxedTyCon is just the negation of isPrimTyCon.
-isBoxedTyCon = not . isPrimTyCon
-
--- isDataTyCon returns False for @newtype@.
--- Not sure about this decision yet.
-isDataTyCon (DataTyCon _ _ _ _ _ _ _ DataType) = True
-isDataTyCon (TupleTyCon _ _ _) = True
-isDataTyCon other = False
-
-isNewTyCon (DataTyCon _ _ _ _ _ _ _ NewType) = True
-isNewTyCon other = False
-
-isSynTyCon (SynTyCon _ _ _ _ _ _) = True
-isSynTyCon _ = False
+data TyCon
+ = FunTyCon {
+ tyConUnique :: Unique,
+ tyConName :: Name,
+ tyConKind :: Kind,
+ tyConArity :: Arity
+ }
+
+
+ | AlgTyCon { -- Data type, and newtype decls.
+ -- All lifted, all boxed
+ tyConUnique :: Unique,
+ tyConName :: Name,
+ tyConKind :: Kind,
+ tyConArity :: Arity,
+
+ tyConTyVars :: [TyVar], -- Scopes over (a) the [PredType] in AlgTyConRhs.DataTyCon
+ -- (b) the cached types in AlgTyConRhs.NewTyCon
+ -- (c) the types in algTcFields
+ -- But not over the data constructors
+ argVrcs :: ArgVrcs,
+
+ algTcFields :: [(FieldLabel, Type, Id)],
+ -- Its fields (empty if none):
+ -- * field name
+ -- * its type (scoped over tby tyConTyVars)
+ -- * record selector (name = field name)
+
+ algTcRhs :: AlgTyConRhs, -- Data constructors in here
+
+ algTcRec :: RecFlag, -- Tells whether the data type is part of
+ -- a mutually-recursive group or not
+
+ hasGenerics :: Bool, -- True <=> generic to/from functions are available
+ -- (in the exports of the data type's source module)
+
+ algTcClass :: Maybe Class
+ -- Just cl if this tycon came from a class declaration
+ }
+
+ | PrimTyCon { -- Primitive types; cannot be defined in Haskell
+ -- Now includes foreign-imported types
+ tyConUnique :: Unique,
+ tyConName :: Name,
+ tyConKind :: Kind,
+ tyConArity :: Arity,
+ argVrcs :: ArgVrcs,
+
+ primTyConRep :: PrimRep,
+ -- Many primitive tycons are unboxed, but some are
+ -- boxed (represented by pointers). The CgRep tells.
+
+ isUnLifted :: Bool, -- Most primitive tycons are unlifted,
+ -- but foreign-imported ones may not be
+ tyConExtName :: Maybe FastString -- Just xx for foreign-imported types
+ }
+
+ | TupleTyCon {
+ tyConUnique :: Unique,
+ tyConName :: Name,
+ tyConKind :: Kind,
+ tyConArity :: Arity,
+ tyConBoxed :: Boxity,
+ tyConTyVars :: [TyVar],
+ dataCon :: DataCon,
+ hasGenerics :: Bool
+ }
+
+ | 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.
+ argVrcs :: ArgVrcs
+ }
+
+type FieldLabel = Name
+
+type ArgVrcs = [(Bool,Bool)] -- Tyvar variance info: [(occPos,occNeg)]
+ -- [] means "no information, assume the worst"
+
+data AlgTyConRhs
+ = AbstractTyCon -- We know nothing about this data type, except
+ -- that it's represented by a pointer
+ -- Used when we export a data type abstractly into
+ -- an hi file
+
+ | DataTyCon
+ (Maybe [PredType]) -- Just theta => this tycon was declared in H98 syntax
+ -- with the specified "stupid theta"
+ -- e.g. data Ord a => T a = ...
+ -- Nothing => this tycon was declared by giving the
+ -- type signatures for each constructor
+ -- (new GADT stuff)
+ -- e.g. data T a where { ... }
+ [DataCon] -- The constructors; can be empty if the user declares
+ -- the type to have no constructors
+ -- INVARIANT: Kept in order of increasing tag
+ -- (see the tag assignment in DataCon.mkDataCon)
+ Bool -- Cached: True <=> an enumeration type
+
+ | NewTyCon -- Newtypes always have exactly one constructor
+ DataCon -- The unique constructor; it has no existentials
+ Type -- Cached: the argument type of the constructor
+ -- = the representation type of the tycon
+
+ Type -- Cached: the *ultimate* representation type
+ -- By 'ultimate' I mean that the rep type is not itself
+ -- a newtype or type synonym.
+ -- The rep type isn't entirely simple:
+ -- for a recursive newtype we pick () as the rep type
+ -- newtype T = MkT T
+ --
+ -- The rep type has free type variables the tyConTyVars
+ -- Thus:
+ -- newtype T a = MkT [(a,Int)]
+ -- The rep type is [(a,Int)]
+ -- NB: the rep type isn't necessarily the original RHS of the
+ -- newtype decl, because the rep type looks through other
+ -- newtypes.
+
+visibleDataCons :: AlgTyConRhs -> [DataCon]
+visibleDataCons AbstractTyCon = []
+visibleDataCons (DataTyCon _ cs _) = cs
+visibleDataCons (NewTyCon c _ _) = [c]