DataCon

ghc-7.8.2: The GHC API

Safe Haskell | None
Language | Haskell98

DataCon

Contents

- Main data types
  - Type construction
  - Type deconstruction
  - Predicates on DataCons
  - Promotion related functions

Synopsis

- data DataCon
- data DataConRep
  - = NoDataConRep
  - | DCR {
    - dcr_wrap_id :: Id
    - dcr_boxer :: DataConBoxer
    - dcr_arg_tys :: [Type]
    - dcr_stricts :: [StrictnessMark]
    - dcr_bangs :: [HsBang]
    }
- data HsBang
  - = HsUserBang (Maybe Bool) Bool
  - | HsNoBang
  - | HsUnpack (Maybe Coercion)
  - | HsStrict
- data StrictnessMark
  - = MarkedStrict
  - | NotMarkedStrict
- type ConTag = Int
- mkDataCon :: Name -> Bool -> [HsBang] -> [FieldLabel] -> [TyVar] -> [TyVar] -> [(TyVar, Type)] -> ThetaType -> [Type] -> Type -> TyCon -> ThetaType -> Id -> DataConRep -> DataCon
- fIRST_TAG :: ConTag
- buildAlgTyCon :: Name -> [TyVar] -> [Role] -> Maybe CType -> ThetaType -> AlgTyConRhs -> RecFlag -> Bool -> Bool -> TyConParent -> TyCon
- dataConRepType :: DataCon -> Type
- dataConSig :: DataCon -> ([TyVar], ThetaType, [Type], Type)
- dataConFullSig :: DataCon -> ([TyVar], [TyVar], [(TyVar, Type)], ThetaType, [Type], Type)
- dataConName :: DataCon -> Name
- dataConIdentity :: DataCon -> [Word8]
- dataConTag :: DataCon -> ConTag
- dataConTyCon :: DataCon -> TyCon
- dataConOrigTyCon :: DataCon -> TyCon
- dataConUserType :: DataCon -> Type
- dataConUnivTyVars :: DataCon -> [TyVar]
- dataConExTyVars :: DataCon -> [TyVar]
- dataConAllTyVars :: DataCon -> [TyVar]
- dataConEqSpec :: DataCon -> [(TyVar, Type)]
- eqSpecPreds :: [(TyVar, Type)] -> ThetaType
- dataConTheta :: DataCon -> ThetaType
- dataConStupidTheta :: DataCon -> ThetaType
- dataConInstArgTys :: DataCon -> [Type] -> [Type]
- dataConOrigArgTys :: DataCon -> [Type]
- dataConOrigResTy :: DataCon -> Type
- dataConInstOrigArgTys :: DataCon -> [Type] -> [Type]
- dataConRepArgTys :: DataCon -> [Type]
- dataConFieldLabels :: DataCon -> [FieldLabel]
- dataConFieldType :: DataCon -> FieldLabel -> Type
- dataConStrictMarks :: DataCon -> [HsBang]
- dataConSourceArity :: DataCon -> Arity
- dataConRepArity :: DataCon -> Arity
- dataConRepRepArity :: DataCon -> RepArity
- dataConIsInfix :: DataCon -> Bool
- dataConWorkId :: DataCon -> Id
- dataConWrapId :: DataCon -> Id
- dataConWrapId_maybe :: DataCon -> Maybe Id
- dataConImplicitIds :: DataCon -> [Id]
- dataConRepStrictness :: DataCon -> [StrictnessMark]
- dataConRepBangs :: DataCon -> [HsBang]
- dataConBoxer :: DataCon -> Maybe DataConBoxer
- splitDataProductType_maybe :: Type -> Maybe (TyCon, [Type], DataCon, [Type])
- tyConsOfTyCon :: TyCon -> [TyCon]
- isNullarySrcDataCon :: DataCon -> Bool
- isNullaryRepDataCon :: DataCon -> Bool
- isTupleDataCon :: DataCon -> Bool
- isUnboxedTupleCon :: DataCon -> Bool
- isVanillaDataCon :: DataCon -> Bool
- classDataCon :: Class -> DataCon
- dataConCannotMatch :: [Type] -> DataCon -> Bool
- isBanged :: HsBang -> Bool
- isMarkedStrict :: StrictnessMark -> Bool
- eqHsBang :: HsBang -> HsBang -> Bool
- promoteKind :: Kind -> SuperKind
- promoteDataCon :: DataCon -> TyCon
- promoteDataCon_maybe :: DataCon -> Maybe TyCon

# Main data types

data DataCon Source

A data constructor

Instances

Eq DataCon |
Data DataCon |
Ord DataCon |
OutputableBndr DataCon |
Outputable DataCon |
Uniquable DataCon |
NamedThing DataCon |
Typeable * DataCon |

data DataConRep Source

Constructors

NoDataConRep |
DCR |
Fields dcr_wrap_id :: Id dcr_boxer :: DataConBoxer dcr_arg_tys :: [Type] dcr_stricts :: [StrictnessMark] dcr_bangs :: [HsBang]

data HsBang Source

Constructors

HsUserBang (Maybe Bool) Bool |
HsNoBang |
HsUnpack (Maybe Coercion) |
HsStrict |

Instances

Data HsBang |
Outputable HsBang |
Typeable * HsBang |

data StrictnessMark Source

Constructors

MarkedStrict |
NotMarkedStrict |

Instances

Outputable StrictnessMark |

type ConTag = Int Source

Type of the tags associated with each constructor possibility

## Type construction

mkDataCon Source

Arguments

:: Name |
-> Bool | Is the constructor declared infix?
-> [HsBang] | Strictness annotations written in the source file
-> [FieldLabel] | Field labels for the constructor, if it is a record, otherwise empty
-> [TyVar] | Universally quantified type variables
-> [TyVar] | Existentially quantified type variables
-> [(TyVar, Type)] | GADT equalities
-> ThetaType | Theta-type occuring before the arguments proper
-> [Type] | Original argument types
-> Type | Original result type
-> TyCon | Representation type constructor
-> ThetaType | The "stupid theta", context of the data declaration e.g. `data Eq a => T a ...`
-> Id | Worker Id
-> DataConRep | Representation
-> DataCon |

Build a new data constructor

fIRST_TAG :: ConTag Source

Tags are allocated from here for real constructors

buildAlgTyCon Source

Arguments

:: Name |
-> [TyVar] | Kind variables and type variables
-> [Role] |
-> Maybe CType |
-> ThetaType | Stupid theta
-> AlgTyConRhs |
-> RecFlag |
-> Bool | True = this TyCon is promotable
-> Bool | True = was declared in GADT syntax
-> TyConParent |
-> TyCon |

## Type deconstruction

dataConRepType :: DataCon -> Type Source

The representation type of the data constructor, i.e. the sort type that will represent values of this type at runtime

dataConSig :: DataCon -> ([TyVar], ThetaType, [Type], Type) Source

The "signature" of the `DataCon` returns, in order:

1) The result of `dataConAllTyVars`,

2) All the `ThetaType`s relating to the `DataCon` (coercion, dictionary, implicit parameter - whatever)

3) The type arguments to the constructor

4) The original result type of the `DataCon`

dataConFullSig :: DataCon -> ([TyVar], [TyVar], [(TyVar, Type)], ThetaType, [Type], Type) Source

The "full signature" of the `DataCon` returns, in order:

1) The result of `dataConUnivTyVars`

2) The result of `dataConExTyVars`

3) The result of `dataConEqSpec`

4) The result of `dataConDictTheta`

5) The original argument types to the `DataCon` (i.e. before any change of the representation of the type)

6) The original result type of the `DataCon`

dataConName :: DataCon -> Name Source

The `Name` of the `DataCon`, giving it a unique, rooted identification

dataConIdentity :: DataCon -> [Word8] Source

The string `package:module.name` identifying a constructor, which is attached to its info table and used by the GHCi debugger and the heap profiler

dataConTag :: DataCon -> ConTag Source

The tag used for ordering `DataCon`s

dataConTyCon :: DataCon -> TyCon Source

The type constructor that we are building via this data constructor

dataConOrigTyCon :: DataCon -> TyCon Source

The original type constructor used in the definition of this data constructor. In case of a data family instance, that will be the family type constructor.

dataConUserType :: DataCon -> Type Source

The user-declared type of the data constructor in the nice-to-read form:

    T :: forall a b. a -> b -> T [a]

rather than:

    T :: forall a c. forall b. (c~[a]) => a -> b -> T c

NB: If the constructor is part of a data instance, the result type mentions the family tycon, not the internal one.

dataConUnivTyVars :: DataCon -> [TyVar] Source

The universally-quantified type variables of the constructor

dataConExTyVars :: DataCon -> [TyVar] Source

The existentially-quantified type variables of the constructor

dataConAllTyVars :: DataCon -> [TyVar] Source

Both the universal and existentiatial type variables of the constructor

dataConEqSpec :: DataCon -> [(TyVar, Type)] Source

Equalities derived from the result type of the data constructor, as written by the programmer in any GADT declaration

eqSpecPreds :: [(TyVar, Type)] -> ThetaType Source

dataConTheta :: DataCon -> ThetaType Source

The *full* constraints on the constructor type

dataConStupidTheta :: DataCon -> ThetaType Source

The "stupid theta" of the `DataCon`, such as `data Eq a` in:

    data Eq a => T a = ...

dataConInstArgTys Source

Arguments

:: DataCon | A datacon with no existentials or equality constraints However, it can have a dcTheta (notably it can be a class dictionary, with superclasses)
-> [Type] | Instantiated at these types
-> [Type] |

Finds the instantiated types of the arguments required to construct a `DataCon` representation NB: these INCLUDE any dictionary args but EXCLUDE the data-declaration context, which is discarded It's all post-flattening etc; this is a representation type

dataConOrigArgTys :: DataCon -> [Type] Source

Returns the argument types of the wrapper, excluding all dictionary arguments and without substituting for any type variables

dataConOrigResTy :: DataCon -> Type Source

dataConInstOrigArgTys :: DataCon -> [Type] -> [Type] Source

Returns just the instantiated value argument types of a `DataCon`, (excluding dictionary args)

dataConRepArgTys :: DataCon -> [Type] Source

Returns the arg types of the worker, including *all* evidence, after any flattening has been done and without substituting for any type variables

dataConFieldLabels :: DataCon -> [FieldLabel] Source

The labels for the fields of this particular `DataCon`

dataConFieldType :: DataCon -> FieldLabel -> Type Source

Extract the type for any given labelled field of the `DataCon`

dataConStrictMarks :: DataCon -> [HsBang] Source

The strictness markings decided on by the compiler. Does not include those for existential dictionaries. The list is in one-to-one correspondence with the arity of the `DataCon`

dataConSourceArity :: DataCon -> Arity Source

Source-level arity of the data constructor

dataConRepArity :: DataCon -> Arity Source

Gives the number of actual fields in the representation of the data constructor. This may be more than appear in the source code; the extra ones are the existentially quantified dictionaries

dataConRepRepArity :: DataCon -> RepArity Source

The number of fields in the representation of the constructor AFTER taking into account the unpacking of any unboxed tuple fields

dataConIsInfix :: DataCon -> Bool Source

Should the `DataCon` be presented infix?

dataConWorkId :: DataCon -> Id Source

Get the Id of the `DataCon` worker: a function that is the "actual" constructor and has no top level binding in the program. The type may be different from the obvious one written in the source program. Panics if there is no such `Id` for this `DataCon`

dataConWrapId :: DataCon -> Id Source

Returns an Id which looks like the Haskell-source constructor by using the wrapper if it exists (see `dataConWrapId_maybe`) and failing over to the worker (see `dataConWorkId`)

dataConWrapId_maybe :: DataCon -> Maybe Id Source

Get the Id of the `DataCon` wrapper: a function that wraps the "actual" constructor so it has the type visible in the source program: c.f. `dataConWorkId`. Returns Nothing if there is no wrapper, which occurs for an algebraic data constructor and also for a newtype (whose constructor is inlined compulsorily)

dataConImplicitIds :: DataCon -> [Id] Source

Find all the `Id`s implicitly brought into scope by the data constructor. Currently, the union of the `dataConWorkId` and the `dataConWrapId`

dataConRepStrictness :: DataCon -> [StrictnessMark] Source

Give the demands on the arguments of a Core constructor application (Con dc args)

dataConRepBangs :: DataCon -> [HsBang] Source

dataConBoxer :: DataCon -> Maybe DataConBoxer Source

splitDataProductType_maybe Source

Arguments

:: Type | A product type, perhaps
-> Maybe (TyCon, [Type], DataCon, [Type]) |

Extract the type constructor, type argument, data constructor and it's representation argument types from a type if it is a product type.

Precisely, we return `Just` for any type that is all of:

- Concrete (i.e. constructors visible)
- Single-constructor
- Not existentially quantified

Whether the type is a `data` type or a `newtype`

tyConsOfTyCon :: TyCon -> [TyCon] Source

All type constructors used in the definition of this type constructor, recursively. This is used to find out all the type constructors whose data constructors need to be in scope to be allowed to safely coerce under this type constructor in Safe Haskell mode.

## Predicates on DataCons

isNullarySrcDataCon :: DataCon -> Bool Source

Return whether there are any argument types for this `DataCon`s original source type

isNullaryRepDataCon :: DataCon -> Bool Source

Return whether there are any argument types for this `DataCon`s runtime representation type

isTupleDataCon :: DataCon -> Bool Source

isUnboxedTupleCon :: DataCon -> Bool Source

isVanillaDataCon :: DataCon -> Bool Source

Vanilla `DataCon`s are those that are nice boring Haskell 98 constructors

classDataCon :: Class -> DataCon Source

dataConCannotMatch :: [Type] -> DataCon -> Bool Source

isBanged :: HsBang -> Bool Source

isMarkedStrict :: StrictnessMark -> Bool Source

eqHsBang :: HsBang -> HsBang -> Bool Source

## Promotion related functions

promoteKind :: Kind -> SuperKind Source

promoteDataCon :: DataCon -> TyCon Source

promoteDataCon_maybe :: DataCon -> Maybe TyCon Source