ghc-7.10.2: The GHC API

Safe Haskell | None
Language | Haskell2010

Type

Contents

- Main data types representing Types
  - Constructing and deconstructing types
  - Common type constructors
  - Predicates on types
- Main data types representing Kinds
  - Finding the kind of a type
  - Common Kinds and SuperKinds
  - Common Kind type constructors
- Type free variables
- Type comparison
- Forcing evaluation of types
- Other views onto Types
- Type representation for the code generator
- Main type substitution data types
  - Manipulating type substitutions
  - Performing substitution on types and kinds
- Pretty-printing
- Tidying type related things up for printing

Description

Main functions for manipulating types and type-related things

Synopsis

- data TyThing
  - = AnId Id
  - | AConLike ConLike
  - | ATyCon TyCon
  - | ACoAxiom (CoAxiom Branched)
- data Type
- type KindOrType = Type
- type PredType = Type
- type ThetaType = [PredType]
- data Var
- type TyVar = Var
- isTyVar :: Var -> Bool
- mkTyVarTy :: TyVar -> Type
- mkTyVarTys :: [TyVar] -> [Type]
- getTyVar :: String -> Type -> TyVar
- getTyVar_maybe :: Type -> Maybe TyVar
- mkAppTy :: Type -> Type -> Type
- mkAppTys :: Type -> [Type] -> Type
- splitAppTy :: Type -> (Type, Type)
- splitAppTys :: Type -> (Type, [Type])
- splitAppTy_maybe :: Type -> Maybe (Type, Type)
- repSplitAppTy_maybe :: Type -> Maybe (Type, Type)
- mkFunTy :: Type -> Type -> Type
- mkFunTys :: [Type] -> Type -> Type
- splitFunTy :: Type -> (Type, Type)
- splitFunTy_maybe :: Type -> Maybe (Type, Type)
- splitFunTys :: Type -> ([Type], Type)
- splitFunTysN :: Int -> Type -> ([Type], Type)
- funResultTy :: Type -> Type
- funArgTy :: Type -> Type
- zipFunTys :: Outputable a => [a] -> Type -> ([(a, Type)], Type)
- mkTyConApp :: TyCon -> [Type] -> Type
- mkTyConTy :: TyCon -> Type
- tyConAppTyCon_maybe :: Type -> Maybe TyCon
- tyConAppArgs_maybe :: Type -> Maybe [Type]
- tyConAppTyCon :: Type -> TyCon
- tyConAppArgs :: Type -> [Type]
- splitTyConApp_maybe :: Type -> Maybe (TyCon, [Type])
- splitTyConApp :: Type -> (TyCon, [Type])
- tyConAppArgN :: Int -> Type -> Type
- nextRole :: Type -> Role
- mkForAllTy :: TyVar -> Type -> Type
- mkForAllTys :: [TyVar] -> Type -> Type
- splitForAllTy_maybe :: Type -> Maybe (TyVar, Type)
- splitForAllTys :: Type -> ([TyVar], Type)
- mkPiKinds :: [TyVar] -> Kind -> Kind
- mkPiType :: Var -> Type -> Type
- mkPiTypes :: [Var] -> Type -> Type
- applyTy :: Type -> KindOrType -> Type
- applyTys :: Type -> [KindOrType] -> Type
- applyTysD :: SDoc -> Type -> [Type] -> Type
- applyTysX :: [TyVar] -> Type -> [Type] -> Type
- dropForAlls :: Type -> Type
- mkNumLitTy :: Integer -> Type
- isNumLitTy :: Type -> Maybe Integer
- mkStrLitTy :: FastString -> Type
- isStrLitTy :: Type -> Maybe FastString
- coAxNthLHS :: CoAxiom br -> Int -> Type
- newTyConInstRhs :: TyCon -> [Type] -> Type
- mkFamilyTyConApp :: TyCon -> [Type] -> Type
- isDictLikeTy :: Type -> Bool
- mkEqPred :: Type -> Type -> PredType
- mkCoerciblePred :: Type -> Type -> PredType
- mkPrimEqPred :: Type -> Type -> Type
- mkReprPrimEqPred :: Type -> Type -> Type
- mkClassPred :: Class -> [Type] -> PredType
- isClassPred :: PredType -> Bool
- isEqPred :: PredType -> Bool
- isIPPred :: PredType -> Bool
- isIPPred_maybe :: Type -> Maybe (FastString, Type)
- isIPTyCon :: TyCon -> Bool
- isIPClass :: Class -> Bool
- data PredTree
  - = ClassPred Class [Type]
  - | EqPred EqRel Type Type
  - | TuplePred [PredType]
  - | IrredPred PredType
- data EqRel
  - = NomEq
  - | ReprEq
- eqRelRole :: EqRel -> Role
- classifyPredType :: PredType -> PredTree
- getClassPredTys :: PredType -> (Class, [Type])
- getClassPredTys_maybe :: PredType -> Maybe (Class, [Type])
- getEqPredTys :: PredType -> (Type, Type)
- getEqPredTys_maybe :: PredType -> Maybe (Role, Type, Type)
- getEqPredRole :: PredType -> Role
- predTypeEqRel :: PredType -> EqRel
- funTyCon :: TyCon
- isTypeVar :: Var -> Bool
- isKindVar :: Var -> Bool
- allDistinctTyVars :: [KindOrType] -> Bool
- isForAllTy :: Type -> Bool
- isTyVarTy :: Type -> Bool
- isFunTy :: Type -> Bool
- isDictTy :: Type -> Bool
- isPredTy :: Type -> Bool
- isVoidTy :: Type -> Bool
- isUnLiftedType :: Type -> Bool
- isUnboxedTupleType :: Type -> Bool
- isAlgType :: Type -> Bool
- isClosedAlgType :: Type -> Bool
- isPrimitiveType :: Type -> Bool
- isStrictType :: Type -> Bool
- type Kind = Type
- type SimpleKind = Kind
- type MetaKindVar = TyVar
- typeKind :: Type -> Kind
- anyKind :: Kind
- liftedTypeKind :: Kind
- unliftedTypeKind :: Kind
- openTypeKind :: Kind
- constraintKind :: Kind
- superKind :: Kind
- liftedTypeKindTyCon :: TyCon
- openTypeKindTyCon :: TyCon
- unliftedTypeKindTyCon :: TyCon
- constraintKindTyCon :: TyCon
- anyKindTyCon :: TyCon
- tyVarsOfType :: Type -> VarSet
- tyVarsOfTypes :: [Type] -> TyVarSet
- closeOverKinds :: TyVarSet -> TyVarSet
- expandTypeSynonyms :: Type -> Type
- typeSize :: Type -> Int
- varSetElemsKvsFirst :: VarSet -> [TyVar]
- eqType :: Type -> Type -> Bool
- eqTypeX :: RnEnv2 -> Type -> Type -> Bool
- eqTypes :: [Type] -> [Type] -> Bool
- cmpType :: Type -> Type -> Ordering
- cmpTypes :: [Type] -> [Type] -> Ordering
- eqPred :: PredType -> PredType -> Bool
- eqPredX :: RnEnv2 -> PredType -> PredType -> Bool
- cmpPred :: PredType -> PredType -> Ordering
- eqKind :: Kind -> Kind -> Bool
- eqTyVarBndrs :: RnEnv2 -> [TyVar] -> [TyVar] -> Maybe RnEnv2
- seqType :: Type -> ()
- seqTypes :: [Type] -> ()
- coreView :: Type -> Maybe Type
- tcView :: Type -> Maybe Type
- type UnaryType = Type
- data RepType
  - = UbxTupleRep [UnaryType]
  - | UnaryRep UnaryType
- flattenRepType :: RepType -> [UnaryType]
- repType :: Type -> RepType
- tyConsOfType :: Type -> NameEnv TyCon
- typePrimRep :: UnaryType -> PrimRep
- typeRepArity :: Arity -> Type -> RepArity
- type TvSubstEnv = TyVarEnv Type
- data TvSubst = TvSubst InScopeSet TvSubstEnv
- emptyTvSubstEnv :: TvSubstEnv
- emptyTvSubst :: TvSubst
- mkTvSubst :: InScopeSet -> TvSubstEnv -> TvSubst
- mkOpenTvSubst :: TvSubstEnv -> TvSubst
- zipOpenTvSubst :: [TyVar] -> [Type] -> TvSubst
- zipTopTvSubst :: [TyVar] -> [Type] -> TvSubst
- mkTopTvSubst :: [(TyVar, Type)] -> TvSubst
- notElemTvSubst :: CoVar -> TvSubst -> Bool
- getTvSubstEnv :: TvSubst -> TvSubstEnv
- setTvSubstEnv :: TvSubst -> TvSubstEnv -> TvSubst
- zapTvSubstEnv :: TvSubst -> TvSubst
- getTvInScope :: TvSubst -> InScopeSet
- extendTvInScope :: TvSubst -> Var -> TvSubst
- extendTvInScopeList :: TvSubst -> [Var] -> TvSubst
- extendTvSubst :: TvSubst -> TyVar -> Type -> TvSubst
- extendTvSubstList :: TvSubst -> [TyVar] -> [Type] -> TvSubst
- isInScope :: Var -> TvSubst -> Bool
- composeTvSubst :: InScopeSet -> TvSubstEnv -> TvSubstEnv -> TvSubstEnv
- zipTyEnv :: [TyVar] -> [Type] -> TvSubstEnv
- isEmptyTvSubst :: TvSubst -> Bool
- unionTvSubst :: TvSubst -> TvSubst -> TvSubst
- substTy :: TvSubst -> Type -> Type
- substTys :: TvSubst -> [Type] -> [Type]
- substTyWith :: [TyVar] -> [Type] -> Type -> Type
- substTysWith :: [TyVar] -> [Type] -> [Type] -> [Type]
- substTheta :: TvSubst -> ThetaType -> ThetaType
- substTyVar :: TvSubst -> TyVar -> Type
- substTyVars :: TvSubst -> [TyVar] -> [Type]
- substTyVarBndr :: TvSubst -> TyVar -> (TvSubst, TyVar)
- cloneTyVarBndr :: TvSubst -> TyVar -> Unique -> (TvSubst, TyVar)
- deShadowTy :: TyVarSet -> Type -> Type
- lookupTyVar :: TvSubst -> TyVar -> Maybe Type
- substKiWith :: [KindVar] -> [Kind] -> Kind -> Kind
- substKisWith :: [KindVar] -> [Kind] -> [Kind] -> [Kind]
- pprType :: Type -> SDoc
- pprParendType :: Type -> SDoc
- pprTypeApp :: TyCon -> [Type] -> SDoc
- pprTyThingCategory :: TyThing -> SDoc
- pprTyThing :: TyThing -> SDoc
- pprTvBndr :: TyVar -> SDoc
- pprTvBndrs :: [TyVar] -> SDoc
- pprForAll :: [TyVar] -> SDoc
- pprUserForAll :: [TyVar] -> SDoc
- pprSigmaType :: Type -> SDoc
- pprTheta :: ThetaType -> SDoc
- pprThetaArrowTy :: ThetaType -> SDoc
- pprClassPred :: Class -> [Type] -> SDoc
- pprKind :: Kind -> SDoc
- pprParendKind :: Kind -> SDoc
- pprSourceTyCon :: TyCon -> SDoc
- data TyPrec
  - = TopPrec
  - | FunPrec
  - | TyOpPrec
  - | TyConPrec
- maybeParen :: TyPrec -> TyPrec -> SDoc -> SDoc
- pprSigmaTypeExtraCts :: Bool -> Type -> SDoc
- tidyType :: TidyEnv -> Type -> Type
- tidyTypes :: TidyEnv -> [Type] -> [Type]
- tidyOpenType :: TidyEnv -> Type -> (TidyEnv, Type)
- tidyOpenTypes :: TidyEnv -> [Type] -> (TidyEnv, [Type])
- tidyOpenKind :: TidyEnv -> Kind -> (TidyEnv, Kind)
- tidyTyVarBndr :: TidyEnv -> TyVar -> (TidyEnv, TyVar)
- tidyTyVarBndrs :: TidyEnv -> [TyVar] -> (TidyEnv, [TyVar])
- tidyFreeTyVars :: TidyEnv -> TyVarSet -> TidyEnv
- tidyOpenTyVar :: TidyEnv -> TyVar -> (TidyEnv, TyVar)
- tidyOpenTyVars :: TidyEnv -> [TyVar] -> (TidyEnv, [TyVar])
- tidyTyVarOcc :: TidyEnv -> TyVar -> TyVar
- tidyTopType :: Type -> Type
- tidyKind :: TidyEnv -> Kind -> Kind

# Main data types representing Types

Types are one of:

Unboxed
  Iff its representation is other than a pointer Unboxed types are also unlifted.
Lifted
  Iff it has bottom as an element. Closures always have lifted types: i.e. any let-bound identifier in Core must have a lifted type. Operationally, a lifted object is one that can be entered. Only lifted types may be unified with a type variable.
Algebraic
  Iff it is a type with one or more constructors, whether declared with `data` or `newtype`. An algebraic type is one that can be deconstructed with a case expression. This is not the same as lifted types, because we also include unboxed tuples in this classification.
Data
  Iff it is a type declared with `data`, or a boxed tuple.
Primitive
  Iff it is a built-in type that can't be expressed in Haskell.

Currently, all primitive types are unlifted, but that's not necessarily the case: for example, `Int` could be primitive.

Some primitive types are unboxed, such as `Int#`, whereas some are boxed but unlifted (such as `ByteArray#`). The only primitive types that we classify as algebraic are the unboxed tuples.

Some examples of type classifications that may make this a bit clearer are:

    Type         primitive       boxed           lifted          algebraic
    -----------------------------------------------------------------------------
    Int#         Yes             No              No              No
    ByteArray#   Yes             Yes             No              No
    (# a, b #)   Yes             No              No              Yes
    (  a, b  )   No              Yes             Yes             Yes
    [a]          No              Yes             Yes             Yes

A source type is a type that is a separate type as far as the type checker is concerned, but which has a more low-level representation as far as Core-to-Core passes and the rest of the back end is concerned.

You don't normally have to worry about this, as the utility functions in this module will automatically convert a source into a representation type if they are spotted, to the best of it's abilities. If you don't want this to happen, use the equivalent functions from the TcType module.

data TyThing Source

A typecheckable-thing, essentially anything that has a name

Constructors

AnId Id |
AConLike ConLike |
ATyCon TyCon |
ACoAxiom (CoAxiom Branched) |

Instances

Eq TyThing |
Ord TyThing |
Outputable TyThing |
NamedThing TyThing |

data Type Source

The key representation of types within the compiler

Instances

Data Type |
Outputable Type |

type KindOrType = Type Source

type PredType = Type Source

A type of the form `p` of kind `Constraint` represents a value whose type is the Haskell predicate `p`, where a predicate is what occurs before the `=>` in a Haskell type.

We use `PredType` as documentation to mark those types that we guarantee to have this kind.

It can be expanded into its representation, but:

- The type checker must treat it as opaque
- The rest of the compiler treats it as transparent

Consider these examples:

    f :: (Eq a) => a -> Int
    g :: (?x :: Int -> Int) => a -> Int
    h :: (r\l) => {r} => {l::Int | r}

Here the `Eq a` and `?x :: Int -> Int` and `rl` are all called "predicates"

type ThetaType = [PredType] Source

A collection of `PredType`s

data Var Source

Essentially a typed `Name`, that may also contain some additional information about the `Var` and it's use sites.

Instances

Eq Var |
Data Var |
Ord Var |
Outputable Var |
Uniquable Var |
NamedThing Var |
type PostRn Id ty = ty |
type PostTc Id ty = ty |

type TyVar = Var Source

isTyVar :: Var -> Bool Source

## Constructing and deconstructing types

mkTyVarTy :: TyVar -> Type Source

mkTyVarTys :: [TyVar] -> [Type] Source

getTyVar :: String -> Type -> TyVar Source

Attempts to obtain the type variable underlying a `Type`, and panics with the given message if this is not a type variable type. See also `getTyVar_maybe`

getTyVar_maybe :: Type -> Maybe TyVar Source

Attempts to obtain the type variable underlying a `Type`

mkAppTy :: Type -> Type -> Type Source

Applies a type to another, as in e.g. `k a`

mkAppTys :: Type -> [Type] -> Type Source

splitAppTy :: Type -> (Type, Type) Source

Attempts to take a type application apart, as in `splitAppTy_maybe`, and panics if this is not possible

splitAppTys :: Type -> (Type, [Type]) Source

Recursively splits a type as far as is possible, leaving a residual type being applied to and the type arguments applied to it. Never fails, even if that means returning an empty list of type applications.

splitAppTy_maybe :: Type -> Maybe (Type, Type) Source

Attempt to take a type application apart, whether it is a function, type constructor, or plain type application. Note that type family applications are NEVER unsaturated by this!

repSplitAppTy_maybe :: Type -> Maybe (Type, Type) Source

Does the AppTy split as in `splitAppTy_maybe`, but assumes that any Core view stuff is already done

mkFunTy :: Type -> Type -> Type infixr 3 Source

Creates a function type from the given argument and result type

mkFunTys :: [Type] -> Type -> Type Source

splitFunTy :: Type -> (Type, Type) Source

Attempts to extract the argument and result types from a type, and panics if that is not possible. See also `splitFunTy_maybe`

splitFunTy_maybe :: Type -> Maybe (Type, Type) Source

Attempts to extract the argument and result types from a type

splitFunTys :: Type -> ([Type], Type) Source

splitFunTysN :: Int -> Type -> ([Type], Type) Source

Split off exactly the given number argument types, and panics if that is not possible

funResultTy :: Type -> Type Source

Extract the function result type and panic if that is not possible

funArgTy :: Type -> Type Source

Extract the function argument type and panic if that is not possible

zipFunTys :: Outputable a => [a] -> Type -> ([(a, Type)], Type) Source

Splits off argument types from the given type and associating them with the things in the input list from left to right. The final result type is returned, along with the resulting pairs of objects and types, albeit with the list of pairs in reverse order. Panics if there are not enough argument types for the input list.

mkTyConApp :: TyCon -> [Type] -> Type Source

A key function: builds a `TyConApp` or `FunTy` as appropriate to its arguments. Applies its arguments to the constructor from left to right.

mkTyConTy :: TyCon -> Type Source

Create the plain type constructor type which has been applied to no type arguments at all.

tyConAppTyCon_maybe :: Type -> Maybe TyCon Source

The same as `fst . splitTyConApp`

tyConAppArgs_maybe :: Type -> Maybe [Type] Source

The same as `snd . splitTyConApp`

tyConAppTyCon :: Type -> TyCon Source

tyConAppArgs :: Type -> [Type] Source

splitTyConApp_maybe :: Type -> Maybe (TyCon, [Type]) Source

Attempts to tease a type apart into a type constructor and the application of a number of arguments to that constructor

splitTyConApp :: Type -> (TyCon, [Type]) Source

Attempts to tease a type apart into a type constructor and the application of a number of arguments to that constructor. Panics if that is not possible. See also `splitTyConApp_maybe`

tyConAppArgN :: Int -> Type -> Type Source

nextRole :: Type -> Role Source

What is the role assigned to the next parameter of this type? Usually, this will be `Nominal`, but if the type is a `TyConApp`, we may be able to do better. The type does *not* have to be well-kinded when applied for this to work!

mkForAllTy :: TyVar -> Type -> Type Source

mkForAllTys :: [TyVar] -> Type -> Type Source

Wraps foralls over the type using the provided `TyVar`s from left to right

splitForAllTy_maybe :: Type -> Maybe (TyVar, Type) Source

Attempts to take a forall type apart, returning the bound type variable and the remainder of the type

splitForAllTys :: Type -> ([TyVar], Type) Source

Attempts to take a forall type apart, returning all the immediate such bound type variables and the remainder of the type. Always suceeds, even if that means returning an empty list of `TyVar`s

mkPiKinds :: [TyVar] -> Kind -> Kind Source

mkPiType :: Var -> Type -> Type Source

Makes a `(->)` type or a forall type, depending on whether it is given a type variable or a term variable.

mkPiTypes :: [Var] -> Type -> Type Source

`mkPiType` for multiple type or value arguments

applyTy :: Type -> KindOrType -> Type Source

Instantiate a forall type with one or more type arguments. Used when we have a polymorphic function applied to type args:

    f t1 t2

We use `applyTys type-of-f [t1,t2]` to compute the type of the expression. Panics if no application is possible.

applyTys :: Type -> [KindOrType] -> Type Source

This function is interesting because:

1. The function may have more for-alls than there are args
2. Less obviously, it may have fewer for-alls

For case 2. think of:

    applyTys (forall a.a) [forall b.b, Int]

This really can happen, but only (I think) in situations involving undefined. For example: undefined :: forall a. a Term: undefined `(forall b. b->b)` Int This term should have type (Int -> Int), but notice that there are more type args than foralls in `undefined`s type.

applyTysD :: SDoc -> Type -> [Type] -> Type Source

applyTysX :: [TyVar] -> Type -> [Type] -> Type Source

dropForAlls :: Type -> Type Source

Equivalent to `snd . splitForAllTys`

mkNumLitTy :: Integer -> Type Source

isNumLitTy :: Type -> Maybe Integer Source

Is this a numeric literal. We also look through type synonyms.

mkStrLitTy :: FastString -> Type Source

isStrLitTy :: Type -> Maybe FastString Source

Is this a symbol literal. We also look through type synonyms.

coAxNthLHS :: CoAxiom br -> Int -> Type Source

Get the type on the LHS of a coercion induced by a type/data family instance.

newTyConInstRhs :: TyCon -> [Type] -> Type Source

Unwrap one `layer` of newtype on a type constructor and its arguments, using an eta-reduced version of the `newtype` if possible. This requires tys to have at least `newTyConInstArity tycon` elements.

mkFamilyTyConApp :: TyCon -> [Type] -> Type Source

Given a family instance TyCon and its arg types, return the corresponding family type. E.g:

    data family T a
    data instance T (Maybe b) = MkT b

Where the instance tycon is :RTL, so:

    mkFamilyTyConApp :RTL Int  =  T (Maybe Int)

isDictLikeTy :: Type -> Bool Source

mkEqPred :: Type -> Type -> PredType Source

Creates a type equality predicate

mkCoerciblePred :: Type -> Type -> PredType Source

mkPrimEqPred :: Type -> Type -> Type Source

mkReprPrimEqPred :: Type -> Type -> Type Source

mkClassPred :: Class -> [Type] -> PredType Source

isClassPred :: PredType -> Bool Source

isEqPred :: PredType -> Bool Source

isIPPred :: PredType -> Bool Source

isIPPred_maybe :: Type -> Maybe (FastString, Type) Source

isIPTyCon :: TyCon -> Bool Source

isIPClass :: Class -> Bool Source

data PredTree Source

Constructors

ClassPred Class [Type] |
EqPred EqRel Type Type |
TuplePred [PredType] |
IrredPred PredType |

data EqRel Source

A choice of equality relation. This is separate from the type `Role` because `Phantom` does not define a (non-trivial) equality relation.

Constructors

NomEq |
ReprEq |

Instances

Eq EqRel |
Ord EqRel |
Outputable EqRel |

eqRelRole :: EqRel -> Role Source

classifyPredType :: PredType -> PredTree Source

getClassPredTys :: PredType -> (Class, [Type]) Source

getClassPredTys_maybe :: PredType -> Maybe (Class, [Type]) Source

getEqPredTys :: PredType -> (Type, Type) Source

getEqPredTys_maybe :: PredType -> Maybe (Role, Type, Type) Source

getEqPredRole :: PredType -> Role Source

predTypeEqRel :: PredType -> EqRel Source

Get the equality relation relevant for a pred type.

## Common type constructors

funTyCon :: TyCon Source

## Predicates on types

isTypeVar :: Var -> Bool Source

isKindVar :: Var -> Bool Source

allDistinctTyVars :: [KindOrType] -> Bool Source

isForAllTy :: Type -> Bool Source

isTyVarTy :: Type -> Bool Source

isFunTy :: Type -> Bool Source

isDictTy :: Type -> Bool Source

isPredTy :: Type -> Bool Source

isVoidTy :: Type -> Bool Source

isUnLiftedType :: Type -> Bool Source

See Type for what an unlifted type is

isUnboxedTupleType :: Type -> Bool Source

isAlgType :: Type -> Bool Source

See Type for what an algebraic type is. Should only be applied to types, as opposed to e.g. partially saturated type constructors

isClosedAlgType :: Type -> Bool Source

See Type for what an algebraic type is. Should only be applied to types, as opposed to e.g. partially saturated type constructors. Closed type constructors are those with a fixed right hand side, as opposed to e.g. associated types

isPrimitiveType :: Type -> Bool Source

Returns true of types that are opaque to Haskell.

isStrictType :: Type -> Bool Source

Computes whether an argument (or let right hand side) should be computed strictly or lazily, based only on its type. Currently, it's just `isUnLiftedType`.

# Main data types representing Kinds

type Kind = Type Source

The key type representing kinds in the compiler. Invariant: a kind is always in one of these forms:

    FunTy k1 k2
    TyConApp PrimTyCon [...]
    TyVar kv   -- (during inference only)
    ForAll ... -- (for top-level coercions)

type SimpleKind = Kind Source

type MetaKindVar = TyVar Source

## Finding the kind of a type

typeKind :: Type -> Kind Source

## Common Kinds and SuperKinds

anyKind :: Kind Source

See Type for details of the distinction between these `Kind`s

liftedTypeKind :: Kind Source

See Type for details of the distinction between these `Kind`s

unliftedTypeKind :: Kind Source

See Type for details of the distinction between these `Kind`s

openTypeKind :: Kind Source

See Type for details of the distinction between these `Kind`s

constraintKind :: Kind Source

See Type for details of the distinction between these `Kind`s

superKind :: Kind Source

See Type for details of the distinction between these `Kind`s

## Common Kind type constructors

liftedTypeKindTyCon :: TyCon Source

See Type for details of the distinction between the `Kind` `TyCon`s

openTypeKindTyCon :: TyCon Source

See Type for details of the distinction between the `Kind` `TyCon`s

unliftedTypeKindTyCon :: TyCon Source

See Type for details of the distinction between the `Kind` `TyCon`s

constraintKindTyCon :: TyCon Source

See Type for details of the distinction between the `Kind` `TyCon`s

anyKindTyCon :: TyCon Source

See Type for details of the distinction between the `Kind` `TyCon`s

# Type free variables

tyVarsOfType :: Type -> VarSet Source

NB: for type synonyms tyVarsOfType does not expand the synonym tyVarsOfType returns only the free variables of a type For example, tyVarsOfType (a::k) returns {a}, not including the kind variable {k}

tyVarsOfTypes :: [Type] -> TyVarSet Source

closeOverKinds :: TyVarSet -> TyVarSet Source

expandTypeSynonyms :: Type -> Type Source

Expand out all type synonyms. Actually, it'd suffice to expand out just the ones that discard type variables (e.g. type Funny a = Int) But we don't know which those are currently, so we just expand all.

typeSize :: Type -> Int Source

varSetElemsKvsFirst :: VarSet -> [TyVar] Source

# Type comparison

eqType :: Type -> Type -> Bool Source

Type equality on source types. Does not look through `newtypes` or `PredType`s, but it does look through type synonyms. Watch out for horrible hack: See Note [Comparison with OpenTypeKind]

eqTypeX :: RnEnv2 -> Type -> Type -> Bool Source

eqTypes :: [Type] -> [Type] -> Bool Source

cmpType :: Type -> Type -> Ordering Source

cmpTypes :: [Type] -> [Type] -> Ordering Source

eqPred :: PredType -> PredType -> Bool Source

eqPredX :: RnEnv2 -> PredType -> PredType -> Bool Source

cmpPred :: PredType -> PredType -> Ordering Source

eqKind :: Kind -> Kind -> Bool Source

eqTyVarBndrs :: RnEnv2 -> [TyVar] -> [TyVar] -> Maybe RnEnv2 Source

# Forcing evaluation of types

seqType :: Type -> () Source

seqTypes :: [Type] -> () Source

# Other views onto Types

coreView :: Type -> Maybe Type Source

In Core, we "look through" non-recursive newtypes and `PredTypes`: this function tries to obtain a different view of the supplied type given this

Strips off the top layer only of a type to give its underlying representation type. Returns Nothing if there is nothing to look through.

By being non-recursive and inlined, this case analysis gets efficiently joined onto the case analysis that the caller is already doing

tcView :: Type -> Maybe Type Source

Similar to `coreView`, but for the type checker, which just looks through synonyms

type UnaryType = Type Source

data RepType Source

Constructors

UbxTupleRep [UnaryType] |
UnaryRep UnaryType |

flattenRepType :: RepType -> [UnaryType] Source

repType :: Type -> RepType Source

Looks through:

1. For-alls
2. Synonyms
3. Predicates
4. All newtypes, including recursive ones, but not newtype families

It's useful in the back end of the compiler.

tyConsOfType :: Type -> NameEnv TyCon Source

All type constructors occurring in the type; looking through type synonyms, but not newtypes. When it finds a Class, it returns the class TyCon.

# Type representation for the code generator

typePrimRep :: UnaryType -> PrimRep Source

Discovers the primitive representation of a more abstract `UnaryType`

typeRepArity :: Arity -> Type -> RepArity Source

# Main type substitution data types

type TvSubstEnv = TyVarEnv Type Source

A substitution of `Type`s for `TyVar`s and `Kind`s for `KindVar`s

data TvSubst Source

Type substitution

The following invariants must hold of a `TvSubst`:

1. The in-scope set is needed only to guide the generation of fresh uniques
2. In particular, the kind of the type variables in the in-scope set is not relevant
3. The substitution is only applied ONCE! This is because in general such application will not reached a fixed point.

Constructors

TvSubst InScopeSet TvSubstEnv |

## Manipulating type substitutions

emptyTvSubstEnv :: TvSubstEnv Source

emptyTvSubst :: TvSubst Source

mkTvSubst :: InScopeSet -> TvSubstEnv -> TvSubst Source

mkOpenTvSubst :: TvSubstEnv -> TvSubst Source

Generates the in-scope set for the `TvSubst` from the types in the incoming environment, hence "open"

zipOpenTvSubst :: [TyVar] -> [Type] -> TvSubst Source

Generates the in-scope set for the `TvSubst` from the types in the incoming environment, hence "open"

zipTopTvSubst :: [TyVar] -> [Type] -> TvSubst Source

mkTopTvSubst :: [(TyVar, Type)] -> TvSubst Source

Called when doing top-level substitutions. Here we expect that the free vars of the range of the substitution will be empty.

notElemTvSubst :: CoVar -> TvSubst -> Bool Source

getTvSubstEnv :: TvSubst -> TvSubstEnv Source

setTvSubstEnv :: TvSubst -> TvSubstEnv -> TvSubst Source

zapTvSubstEnv :: TvSubst -> TvSubst Source

getTvInScope :: TvSubst -> InScopeSet Source

extendTvInScope :: TvSubst -> Var -> TvSubst Source

extendTvInScopeList :: TvSubst -> [Var] -> TvSubst Source

extendTvSubst :: TvSubst -> TyVar -> Type -> TvSubst Source

extendTvSubstList :: TvSubst -> [TyVar] -> [Type] -> TvSubst Source

isInScope :: Var -> TvSubst -> Bool Source

composeTvSubst :: InScopeSet -> TvSubstEnv -> TvSubstEnv -> TvSubstEnv Source

`(compose env1 env2)(x)` is `env1(env2(x))`; i.e. apply `env2` then `env1`. It assumes that both are idempotent. Typically, `env1` is the refinement to a base substitution `env2`

zipTyEnv :: [TyVar] -> [Type] -> TvSubstEnv Source

isEmptyTvSubst :: TvSubst -> Bool Source

unionTvSubst :: TvSubst -> TvSubst -> TvSubst Source

## Performing substitution on types and kinds

substTy :: TvSubst -> Type -> Type Source

Substitute within a `Type`

substTys :: TvSubst -> [Type] -> [Type] Source

Substitute within several `Type`s

substTyWith :: [TyVar] -> [Type] -> Type -> Type Source

Type substitution making use of an `TvSubst` that is assumed to be open, see `zipOpenTvSubst`

substTysWith :: [TyVar] -> [Type] -> [Type] -> [Type] Source

Type substitution making use of an `TvSubst` that is assumed to be open, see `zipOpenTvSubst`

substTheta :: TvSubst -> ThetaType -> ThetaType Source

Substitute within a `ThetaType`

substTyVar :: TvSubst -> TyVar -> Type Source

substTyVars :: TvSubst -> [TyVar] -> [Type] Source

substTyVarBndr :: TvSubst -> TyVar -> (TvSubst, TyVar) Source

cloneTyVarBndr :: TvSubst -> TyVar -> Unique -> (TvSubst, TyVar) Source

deShadowTy :: TyVarSet -> Type -> Type Source

Remove any nested binders mentioning the `TyVar`s in the `TyVarSet`

lookupTyVar :: TvSubst -> TyVar -> Maybe Type Source

substKiWith :: [KindVar] -> [Kind] -> Kind -> Kind Source

substKisWith :: [KindVar] -> [Kind] -> [Kind] -> [Kind] Source

# Pretty-printing

pprType :: Type -> SDoc Source

pprParendType :: Type -> SDoc Source

pprTypeApp :: TyCon -> [Type] -> SDoc Source

pprTyThingCategory :: TyThing -> SDoc Source

pprTyThing :: TyThing -> SDoc Source

pprTvBndr :: TyVar -> SDoc Source

pprTvBndrs :: [TyVar] -> SDoc Source

pprForAll :: [TyVar] -> SDoc Source

pprUserForAll :: [TyVar] -> SDoc Source

pprSigmaType :: Type -> SDoc Source

pprTheta :: ThetaType -> SDoc Source

pprThetaArrowTy :: ThetaType -> SDoc Source

pprClassPred :: Class -> [Type] -> SDoc Source

pprKind :: Kind -> SDoc Source

pprParendKind :: Kind -> SDoc Source

pprSourceTyCon :: TyCon -> SDoc Source

Pretty prints a `TyCon`, using the family instance in case of a representation tycon. For example:

    data T [a] = ...

In that case we want to print `T [a]`, where `T` is the family `TyCon`

data TyPrec Source

Constructors

TopPrec |
FunPrec |
TyOpPrec |
TyConPrec |

Instances

Eq TyPrec |
Ord TyPrec |

maybeParen :: TyPrec -> TyPrec -> SDoc -> SDoc Source

pprSigmaTypeExtraCts :: Bool -> Type -> SDoc Source

# Tidying type related things up for printing

tidyType :: TidyEnv -> Type -> Type Source

tidyTypes :: TidyEnv -> [Type] -> [Type] Source

tidyOpenType :: TidyEnv -> Type -> (TidyEnv, Type) Source

Grabs the free type variables, tidies them and then uses `tidyType` to work over the type itself

tidyOpenTypes :: TidyEnv -> [Type] -> (TidyEnv, [Type]) Source

tidyOpenKind :: TidyEnv -> Kind -> (TidyEnv, Kind) Source

tidyTyVarBndr :: TidyEnv -> TyVar -> (TidyEnv, TyVar) Source

tidyTyVarBndrs :: TidyEnv -> [TyVar] -> (TidyEnv, [TyVar]) Source

This tidies up a type for printing in an error message, or in an interface file.

It doesn't change the uniques at all, just the print names.

tidyFreeTyVars :: TidyEnv -> TyVarSet -> TidyEnv Source

Add the free `TyVar`s to the env in tidy form, so that we can tidy the type they are free in

tidyOpenTyVar :: TidyEnv -> TyVar -> (TidyEnv, TyVar) Source

Treat a new `TyVar` as a binder, and give it a fresh tidy name using the environment if one has not already been allocated. See also `tidyTyVarBndr`

tidyOpenTyVars :: TidyEnv -> [TyVar] -> (TidyEnv, [TyVar]) Source

tidyTyVarOcc :: TidyEnv -> TyVar -> TyVar Source

tidyTopType :: Type -> Type Source

Calls `tidyType` on a top-level type (i.e. with an empty tidying environment)

tidyKind :: TidyEnv -> Kind -> Kind Source