- = FunTyCon -- Kind = Type -> Type -> Type
-
- | DataTyCon Unique
- Name
- Kind
- [TyVar]
- [(Class,[Type])] -- Its context
- [Id{-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
- [Class] -- Classes which have derived instances
- (Maybe Class) -- Nothing for ordinary types; Just c for the type constructor
- -- for dictionaries of class c.
- NewOrData
- RecFlag -- Tells whether the data type is part of
- -- a mutually-recursive group or not
-
- | 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 unpointed; 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
- Arity -- the thing.
- PrimRep
-
- | 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.
+ = 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
+ -- But not over the data constructors
+ argVrcs :: ArgVrcs,
+
+ algTcSelIds :: [Id], -- Its record selectors (empty if none):
+
+ algTcStupidTheta :: [PredType], -- The "stupid theta" for the data type
+ -- (always empty for GADTs)
+
+ 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
+ synTcRhs :: 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 {
+ data_cons :: [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)
+ is_enum :: Bool -- Cached: True <=> an enumeration type
+ } -- Includes data types with no constructors.
+
+ | NewTyCon {
+ data_con :: DataCon, -- The unique constructor; it has no existentials
+
+ nt_rhs :: Type, -- Cached: the argument type of the constructor
+ -- = the representation type of the tycon
+
+ nt_etad_rhs :: ([TyVar], Type) ,
+ -- The same again, but this time eta-reduced
+ -- hence the [TyVar] which may be shorter than the declared
+ -- arity of the TyCon. See Note [Newtype eta]
+
+ nt_rep :: Type -- Cached: the *ultimate* representation type
+ -- By 'ultimate' I mean that the top-level constructor
+ -- of 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
+ --
+ -- This one does not need to be eta reduced; hence its
+ -- free type variables are conveniently 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{ data_cons = cs }) = cs
+visibleDataCons (NewTyCon{ data_con = c }) = [c]