ghc-8.4.3: The GHC API

TyCon

Synopsis

# Main TyCon data types

data TyCon Source #

TyCons represent type constructors. Type constructors are introduced by things such as:

1) Data declarations: data Foo = ... creates the Foo type constructor of kind *

2) Type synonyms: type Foo = ... creates the Foo type constructor

3) Newtypes: newtype Foo a = MkFoo ... creates the Foo type constructor of kind * -> *

4) Class declarations: class Foo where creates the Foo type constructor of kind *

This data type also encodes a number of primitive, built in type constructors such as those for function and tuple types.

Instances
 Source # Instance detailsDefined in TyCon Methods(==) :: TyCon -> TyCon -> Bool #(/=) :: TyCon -> TyCon -> Bool # Source # Instance detailsDefined in TyCon Methodsgfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> TyCon -> c TyCon #gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c TyCon #dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c TyCon) #dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TyCon) #gmapT :: (forall b. Data b => b -> b) -> TyCon -> TyCon #gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TyCon -> r #gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TyCon -> r #gmapQ :: (forall d. Data d => d -> u) -> TyCon -> [u] #gmapQi :: Int -> (forall d. Data d => d -> u) -> TyCon -> u #gmapM :: Monad m => (forall d. Data d => d -> m d) -> TyCon -> m TyCon #gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> TyCon -> m TyCon #gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> TyCon -> m TyCon # Source # Instance detailsDefined in TyCon Methods Source # Instance detailsDefined in TyCon Methods Source # Instance detailsDefined in TyCon Methods

Represents right-hand-sides of TyCons for algebraic types

Constructors

 AbstractTyCon Says that 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 Information about those TyCons derived from a data declaration. This includes data types with no constructors at all. Fieldsdata_cons :: [DataCon]The data type constructors; can be empty if the user declares the type to have no constructorsINVARIANT: Kept in order of increasing DataCon tag (see the tag assignment in DataCon.mkDataCon)is_enum :: BoolCached value: is this an enumeration type? See Note [Enumeration types] TupleTyCon Fieldsdata_con :: DataConThe unique constructor for the newtype. It has no existentialstup_sort :: TupleSortIs this a boxed, unboxed or constraint tuple? SumTyCon Fieldsdata_cons :: [DataCon]The data type constructors; can be empty if the user declares the type to have no constructorsINVARIANT: Kept in order of increasing DataCon tag (see the tag assignment in DataCon.mkDataCon) NewTyCon Information about those TyCons derived from a newtype declaration Fieldsdata_con :: DataConThe unique constructor for the newtype. It has no existentialsnt_rhs :: TypeCached value: the argument type of the constructor, which is just the representation type of the TyCon (remember that newtypes do not exist at runtime so need a different representation type).The free TyVars of this type are the tyConTyVars from the corresponding TyConnt_etad_rhs :: ([TyVar], Type)Same as the nt_rhs, but this time eta-reduced. Hence the list of TyVars in this field may be shorter than the declared arity of the TyCon.nt_co :: CoAxiom Unbranched

Both type classes as well as family instances imply implicit type constructors. These implicit type constructors refer to their parent structure (ie, the class or family from which they derive) using a type of the following form.

Extract those DataCons that we are able to learn about. Note that visibility in this sense does not correspond to visibility in the context of any particular user program!

Constructors

 VanillaAlgTyCon TyConRepName An ordinary type constructor has no parent. UnboxedAlgTyCon (Maybe TyConRepName) An unboxed type constructor. The TyConRepName is a Maybe since we currently don't allow unboxed sums to be Typeable since there are too many of them. See #13276. ClassTyCon Class TyConRepName Type constructors representing a class dictionary. See Note [ATyCon for classes] in TyCoRep DataFamInstTyCon (CoAxiom Unbranched) TyCon [Type] Type constructors representing an *instance* of a *data* family. Parameters:1) The type family in question2) Instance types; free variables are the tyConTyVars of the current TyCon (not the family one). INVARIANT: the number of types matches the arity of the family TyCon3) A CoTyCon identifying the representation type with the type instance family
Instances
 Source # Instance detailsDefined in TyCon Methods

Information pertaining to the expansion of a type synonym (type)

Constructors

 DataFamilyTyCon TyConRepName Represents an open type family without a fixed right hand side. Additional instances can appear at any time.These are introduced by either a top level declaration:data family T a :: *Or an associated data type declaration, within a class declaration:class C a b where data T b :: * OpenSynFamilyTyCon An open type synonym family e.g. type family F x y :: * -> * ClosedSynFamilyTyCon (Maybe (CoAxiom Branched)) A closed type synonym family e.g. type family F x where { F Int = Bool } AbstractClosedSynFamilyTyCon A closed type synonym family declared in an hs-boot file with type family F a where .. BuiltInSynFamTyCon BuiltInSynFamily Built-in type family used by the TypeNats solver
Instances
 Source # Instance detailsDefined in TyCon Methods

data Role Source #

Constructors

 Nominal Representational Phantom
Instances
 Source # Instance detailsDefined in CoAxiom Methods(==) :: Role -> Role -> Bool #(/=) :: Role -> Role -> Bool # Source # Instance detailsDefined in CoAxiom Methodsgfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Role -> c Role #gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Role #dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Role) #dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Role) #gmapT :: (forall b. Data b => b -> b) -> Role -> Role #gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Role -> r #gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Role -> r #gmapQ :: (forall d. Data d => d -> u) -> Role -> [u] #gmapQi :: Int -> (forall d. Data d => d -> u) -> Role -> u #gmapM :: Monad m => (forall d. Data d => d -> m d) -> Role -> m Role #gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Role -> m Role #gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Role -> m Role # Source # Instance detailsDefined in CoAxiom Methodscompare :: Role -> Role -> Ordering #(<) :: Role -> Role -> Bool #(<=) :: Role -> Role -> Bool #(>) :: Role -> Role -> Bool #(>=) :: Role -> Role -> Bool #max :: Role -> Role -> Role #min :: Role -> Role -> Role # Source # Instance detailsDefined in CoAxiom Methods Source # Instance detailsDefined in CoAxiom Methodsput_ :: BinHandle -> Role -> IO () Source #put :: BinHandle -> Role -> IO (Bin Role) Source #

Constructors

 NotInjective Injective [Bool]
Instances
 Source # Instance detailsDefined in TyCon Methods Source # Instance detailsDefined in TyCon Methods

Some promoted datacons signify extra info relevant to GHC. For example, the IntRep constructor of RuntimeRep corresponds to the IntRep constructor of PrimRep. This data structure allows us to store this information right in the TyCon. The other approach would be to look up things like RuntimeRep's PrimRep by known-key every time.

Constructors

 NoRRI an ordinary promoted data con RuntimeRep ([Type] -> [PrimRep]) A constructor of RuntimeRep. The argument to the function should be the list of arguments to the promoted datacon. VecCount Int A constructor of VecCount VecElem PrimElemRep A constructor of VecElem

Paints a picture of what a TyCon represents, in broad strokes. This is used towards more informative error messages.

Constructors

 ClassFlavour TupleFlavour Boxity SumFlavour DataTypeFlavour NewtypeFlavour AbstractTypeFlavour DataFamilyFlavour OpenTypeFamilyFlavour ClosedTypeFamilyFlavour TypeSynonymFlavour BuiltInTypeFlavour e.g., the (->) TyCon. PromotedDataConFlavour
Instances
 Source # Instance detailsDefined in TyCon Methods Source # Instance detailsDefined in TyCon Methods

# TyConBinder

Constructors

 NamedTCB ArgFlag AnonTCB
Instances
 Source # Instance detailsDefined in TyCon Methods Source # Instance detailsDefined in TyCon Methods

## Field labels

The labels for the fields of this particular TyCon

Look up a field label belonging to this TyCon

## Constructing TyCons

Arguments

 :: Name -> [TyConBinder] Binders of the TyCon -> Kind Result kind -> [Role] The roles for each TyVar -> Maybe CType The C type this type corresponds to when using the CAPI FFI -> [PredType] Stupid theta: see algTcStupidTheta -> AlgTyConRhs Information about data constructors -> AlgTyConFlav What flavour is it? (e.g. vanilla, type family) -> Bool Was the TyCon declared with GADT syntax? -> TyCon

This is the making of an algebraic TyCon. Notably, you have to pass in the generic (in the -XGenerics sense) information about the type constructor - you can get hold of it easily (see Generics module)

mkClassTyCon :: Name -> [TyConBinder] -> [Role] -> AlgTyConRhs -> Class -> Name -> TyCon Source #

Simpler specialization of mkAlgTyCon for classes

mkFunTyCon :: Name -> [TyConBinder] -> Name -> TyCon Source #

Given the name of the function type constructor and it's kind, create the corresponding TyCon. It is recomended to use funTyCon if you want this functionality

Arguments

 :: Name -> [TyConBinder] -> Kind result kind, never levity-polymorphic -> [Role] -> TyCon

Create an unlifted primitive TyCon, such as Int#.

Arguments

 :: Name -> [TyConBinder] -> Kind result kind -> [Role] -> Name -> TyCon

Kind constructors

Arguments

 :: Name -> [TyConBinder] -> Kind result kind -> [Role] -> TyCon

Create a lifted primitive TyCon such as RealWorld

Arguments

 :: Name -> [TyConBinder] -> Kind Result kind of the TyCon -> Arity Arity of the tuple TyCon -> DataCon -> TupleSort Whether the tuple is boxed or unboxed -> AlgTyConFlav -> TyCon

Arguments

 :: Name -> [TyConBinder] -> Kind Kind of the resulting TyCon -> Arity Arity of the sum -> [TyVar] TyVars scoped over: see tyConTyVars -> [DataCon] -> AlgTyConFlav -> TyCon

Arguments

 :: Name -> [TyConBinder] -> Kind result kind -> [Role] -> Type -> Bool -> Bool -> TyCon

Create a type synonym TyCon

Arguments

 :: Name -> [TyConBinder] -> Kind result kind -> Maybe Name -> FamTyConFlav -> Maybe Class -> Injectivity -> TyCon

Create a type family TyCon

mkPromotedDataCon :: DataCon -> Name -> TyConRepName -> [TyConBinder] -> Kind -> [Role] -> RuntimeRepInfo -> TyCon Source #

Create a promoted data constructor TyCon Somewhat dodgily, we give it the same Name as the data constructor itself; when we pretty-print the TyCon we add a quote; see the Outputable TyCon instance

Arguments

 :: Name -> [TyConBinder] -> Kind result kind only -> [(Name, TyVar)] Scoped type variables; see Note [How TcTyCons work] in TcTyClsDecls -> TyConFlavour What sort of TyCon this represents -> TyCon

Makes a tycon suitable for use during type-checking. The only real need for this is for printing error messages during a recursive type/class type-checking knot. It has a kind because TcErrors sometimes calls typeKind. See also Note [Kind checking recursive type and class declarations] in TcTyClsDecls.

## Predicates on TyCons

Returns True if the supplied TyCon resulted from either a data or newtype declaration

Returns True for vanilla AlgTyCons -- that is, those created with a data or newtype declaration.

Is this TyCon that for a class instance?

Is this TyCon that for a data family instance?

Does this TyCon represent something that cannot be defined in Haskell?

Does this TyCon represent a tuple?

NB: when compiling Data.Tuple, the tycons won't reply True to isTupleTyCon, because they are built as AlgTyCons. However they get spat into the interface file as tuple tycons, so I don't think it matters.

Is this the TyCon for an unboxed tuple?

Is this the TyCon for a boxed tuple?

Is this the TyCon for an unboxed sum?

Is this the TyCon for a promoted tuple?

Is this a TyCon representing a regular H98 type synonym (type)?

True iff we can decompose (T a b c) into ((T a b) c) I.e. is it injective and generative w.r.t nominal equality? That is, if (T a b) ~N d e f, is it always the case that (T ~N d), (a ~N e) and (b ~N f)? Specifically NOT true of synonyms (open and otherwise)

It'd be unusual to call mightBeUnsaturatedTyCon on a regular H98 type synonym, because you should probably have expanded it first But regardless, it's not decomposable

Is this a PromotedDataCon?

Retrieves the promoted DataCon if this is a PromotedDataCon;

Is this tycon really meant for use at the kind level? That is, should it be permitted without -XDataKinds?

Returns True for data types that are definitely represented by heap-allocated constructors. These are scrutinised by Core-level case expressions, and they get info tables allocated for them.

Generally, the function will be true for all data types and false for newtypes, unboxed tuples, unboxed sums and type family TyCons. But it is not guaranteed to return True in all cases that it could.

NB: for a data type family, only the instance TyCons get an info table. The family declaration TyCon does not

Is this an algebraic TyCon which is just an enumeration of values?

Is this TyCon that for a newtype

Test if the TyCon is algebraic but abstract (invisible data constructors)

Is this a TyCon, synonym or otherwise, that defines a family?

Is this a TyCon, synonym or otherwise, that defines a family with instances?

Is this a synonym TyCon that can have may have further instances appear?

Is this a synonym TyCon that can have may have further instances appear?

Is this an open type family TyCon?

Is this a non-empty closed type family? Returns Nothing for abstract or empty closed families.

tyConInjectivityInfo tc returns Injective is is tc is an injective tycon (where is states for which tyConBinders tc is injective), or NotInjective otherwise.

Is this TyCon unlifted (i.e. cannot contain bottom)? Note that this can only be true for primitive and unboxed-tuple TyCons

Is this an algebraic TyCon declared with the GADT syntax?

isInjectiveTyCon is true of TyCons for which this property holds (where X is the role passed in): If (T a1 b1 c1) ~X (T a2 b2 c2), then (a1 ~X1 a2), (b1 ~X2 b2), and (c1 ~X3 c2) (where X1, X2, and X3, are the roles given by tyConRolesX tc X) See also Note [Decomposing equality] in TcCanonical

isGenerativeTyCon is true of TyCons for which this property holds (where X is the role passed in): If (T tys ~X t), then (t's head ~X T). See also Note [Decomposing equality] in TcCanonical

Is this an AlgTyConRhs of a TyCon that is generative and injective with respect to representational equality?

Are we able to extract information TyVar to class argument list mapping from a given TyCon?

Identifies implicit tycons that, in particular, do not go into interface files (because they are implicitly reconstructed when the interface is read).

Note that:

• Associated families are implicit, as they are re-constructed from the class declaration in which they reside, and
• Family instances are not implicit as they represent the instance body (similar to a dfun does that for a class instance).
• Tuples are implicit iff they have a wired-in name (namely: boxed and unboxed tupeles are wired-in and implicit, but constraint tuples are not)

Check if the tycon actually refers to a proper data or newtype with user defined constructors rather than one from a class or other construction.

Is this a TcTyCon? (That is, one only used during type-checking?)

Could this TyCon ever be levity-polymorphic when fully applied? True is safe. False means we're sure. Does only a quick check based on the TyCon's category. Precondition: The fully-applied TyCon has kind (TYPE blah)

## Extracting information out of TyCons

Name of the constructor

Returns whether or not this TyCon is definite, or a hole that may be filled in at some later point. See Note [Skolem abstract data]

Kind of this TyCon

A Unique of this TyCon. Invariant: identical to Unique of Name stored in tyConName field.

tyConTyVars :: TyCon -> [TyVar] Source #

TyVar binders

The C type that should be used for this type when using the FFI and CAPI

As tyConDataCons_maybe, but returns the empty list of constructors if no constructors could be found

Determine the DataCons originating from the given TyCon, if the TyCon is the sort that can have any constructors (note: this does not include abstract algebraic types)

If the given TyCon has a single data constructor, i.e. it is a data type with one alternative, a tuple type or a newtype then that constructor is returned. If the TyCon has more than one constructor, or represents a primitive or function type constructor then Nothing is returned. In any other case, the function panics

Determine the number of value constructors a TyCon has. Panics if the TyCon is not algebraic or a tuple

Determine if number of value constructors a TyCon has is smaller than n. Faster than tyConFamilySize tc <= n. Panics if the TyCon is not algebraic or a tuple

Find the "stupid theta" of the TyCon. A "stupid theta" is the context to the left of an algebraic type declaration, e.g. Eq a in the declaration data Eq a => T a ...

Arity

tyConRoles :: TyCon -> [Role] Source #

Get the list of roles for the type parameters of a TyCon

If this TyCon is that for a class instance, return the class it is for. Otherwise returns Nothing

tyConATs :: TyCon -> [TyCon] Source #

Return the associated types of the TyCon, if any

If this TyCon is that of a data family instance, return the family in question and the instance types. Otherwise, return Nothing

If this TyCon is that of a data family instance, return a TyCon which represents a coercion identifying the representation type with the type instance family. Otherwise, return Nothing

Extract type variable naming the result of injective type family

Extract the TyVars bound by a vanilla type synonym and the corresponding (unsubstituted) right hand side.

Extract the information pertaining to the right hand side of a type synonym (type) declaration.

Extract the flavour of a type family (with all the extra information that it carries)

Name of result type variable, used for pretty-printing with --show-iface and for reifying TyCon in Template Haskell

Extract an AlgTyConRhs with information about data constructors from an algebraic or tuple TyCon. Panics for any other sort of TyCon

newTyConRhs :: TyCon -> ([TyVar], Type) Source #

Extract the bound type variables and type expansion of a type synonym TyCon. Panics if the TyCon is not a synonym

The number of type parameters that need to be passed to a newtype to resolve it. May be less than in the definition if it can be eta-contracted.

newTyConEtadRhs :: TyCon -> ([TyVar], Type) Source #

Extract the bound type variables and type expansion of an eta-contracted type synonym TyCon. Panics if the TyCon is not a synonym

Take a TyCon apart into the TyVars it scopes over, the Type it expands into, and (possibly) a coercion from the representation type to the newtype. Returns Nothing if this is not possible.

Maps a label to information about the field

Extract any RuntimeRepInfo from this TyCon

Full binders

Result kind

tcTyConScopedTyVars :: TyCon -> [(Name, TyVar)] Source #

Scoped tyvars over the tycon's body See Note [How TcTyCons work] in TcTyClsDecls

## Manipulating TyCons

Arguments

 :: TyCon -> [tyco] Arguments to TyCon -> Maybe ([(TyVar, tyco)], Type, [tyco]) Returns a TyVar substitution, the body type of the synonym (not yet substituted) and any arguments remaining from the application

Expand a type synonym application, if any

Make a fake, recovery TyCon from an existing one. Used when recovering from errors

Extracts the newtype coercion from such a TyCon, which can be used to construct something with the newtypes type from its representation type (right hand side). If the supplied TyCon is not a newtype, returns Nothing

## Predicated on TyConFlavours

Can this flavour of TyCon appear unsaturated?

Is this flavour of TyCon an open type family or a data family?

# Runtime type representation

Make a Name for the Typeable representation of the given wired-in type

The name (and defining module) for the Typeable representation (TyCon) of a type constructor.

See Note [Grand plan for Typeable] in TcTypeable in TcTypeable.

# Primitive representations of Types

data PrimRep Source #

A PrimRep is an abstraction of a type. It contains information that the code generator needs in order to pass arguments, return results, and store values of this type.

Constructors

 VoidRep LiftedRep UnliftedRep Unlifted pointer IntRep Signed, word-sized value WordRep Unsigned, word-sized value Int64Rep Signed, 64 bit value (with 32-bit words only) Word64Rep Unsigned, 64 bit value (with 32-bit words only) AddrRep A pointer, but not to a Haskell value (use '(Un)liftedRep') FloatRep DoubleRep VecRep Int PrimElemRep A vector
Instances
 Source # Instance detailsDefined in TyCon Methods(==) :: PrimRep -> PrimRep -> Bool #(/=) :: PrimRep -> PrimRep -> Bool # Source # Instance detailsDefined in TyCon MethodsshowList :: [PrimRep] -> ShowS # Source # Instance detailsDefined in TyCon Methods
Instances
 Source # Instance detailsDefined in TyCon Methods Source # Instance detailsDefined in TyCon MethodsshowList :: [PrimElemRep] -> ShowS # Source # Instance detailsDefined in TyCon Methods

The size of a PrimRep in bytes.

This applies also when used in a constructor, where we allow packing the fields. For instance, in data Foo = Foo Float the two fields will take only 8 bytes, which for 64-bit arch will be equal to 1 word. See also mkVirtHeapOffsetsWithPadding for details of how data fields are layed out.

Return if Rep stands for floating type, returns Nothing for vector types.