Type

ghc-8.4.4: The GHC API

Safe Haskell | None
Language | Haskell2010

Type

Contents

- Main data types representing Types
  - Constructing and deconstructing types
  - Binders
  - Common type constructors
  - Predicates on types
- Main data types representing Kinds
  - Finding the kind of a type
  - Common Kind
- Type free variables
- Well-scoped lists of variables
- Type comparison
- Forcing evaluation of types
- Other views onto Types
- 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
- data ArgFlag
  - = Required
  - | Specified
  - | Inferred
- type KindOrType = Type
- type PredType = Type
- type ThetaType = [PredType]
- data Var
- type TyVar = Var
- isTyVar :: Var -> Bool
- type TyCoVar = Id
- data TyBinder
- type TyVarBinder = TyVarBndr TyVar ArgFlag
- mkTyVarTy :: TyVar -> Type
- mkTyVarTys :: [TyVar] -> [Type]
- getTyVar :: String -> Type -> TyVar
- getTyVar_maybe :: Type -> Maybe TyVar
- repGetTyVar_maybe :: Type -> Maybe TyVar
- getCastedTyVar_maybe :: Type -> Maybe (TyVar, CoercionN)
- tyVarKind :: TyVar -> Kind
- mkAppTy :: Type -> Type -> Type
- mkAppTys :: Type -> [Type] -> Type
- splitAppTy :: Type -> (Type, Type)
- splitAppTys :: Type -> (Type, [Type])
- repSplitAppTys :: HasDebugCallStack => Type -> (Type, [Type])
- splitAppTy_maybe :: Type -> Maybe (Type, Type)
- repSplitAppTy_maybe :: HasDebugCallStack => Type -> Maybe (Type, Type)
- tcRepSplitAppTy_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)
- funResultTy :: Type -> Type
- funArgTy :: Type -> Type
- mkTyConApp :: TyCon -> [Type] -> Type
- mkTyConTy :: TyCon -> Type
- tyConAppTyCon_maybe :: Type -> Maybe TyCon
- tyConAppTyConPicky_maybe :: Type -> Maybe TyCon
- tyConAppArgs_maybe :: Type -> Maybe [Type]
- tyConAppTyCon :: Type -> TyCon
- tyConAppArgs :: Type -> [Type]
- splitTyConApp_maybe :: HasDebugCallStack => Type -> Maybe (TyCon, [Type])
- splitTyConApp :: Type -> (TyCon, [Type])
- tyConAppArgN :: Int -> Type -> Type
- nextRole :: Type -> Role
- tcRepSplitTyConApp_maybe :: HasCallStack => Type -> Maybe (TyCon, [Type])
- tcSplitTyConApp_maybe :: HasCallStack => Type -> Maybe (TyCon, [Type])
- splitListTyConApp_maybe :: Type -> Maybe Type
- repSplitTyConApp_maybe :: HasDebugCallStack => Type -> Maybe (TyCon, [Type])
- mkForAllTy :: TyVar -> ArgFlag -> Type -> Type
- mkForAllTys :: [TyVarBinder] -> Type -> Type
- mkInvForAllTys :: [TyVar] -> Type -> Type
- mkSpecForAllTys :: [TyVar] -> Type -> Type
- mkVisForAllTys :: [TyVar] -> Type -> Type
- mkInvForAllTy :: TyVar -> Type -> Type
- splitForAllTys :: Type -> ([TyVar], Type)
- splitForAllTyVarBndrs :: Type -> ([TyVarBinder], Type)
- splitForAllTy_maybe :: Type -> Maybe (TyVar, Type)
- splitForAllTy :: Type -> (TyVar, Type)
- splitPiTy_maybe :: Type -> Maybe (TyBinder, Type)
- splitPiTy :: Type -> (TyBinder, Type)
- splitPiTys :: Type -> ([TyBinder], Type)
- mkPiTy :: TyBinder -> Type -> Type
- mkPiTys :: [TyBinder] -> Type -> Type
- mkTyConBindersPreferAnon :: [TyVar] -> Type -> [TyConBinder]
- mkLamType :: Var -> Type -> Type
- mkLamTypes :: [Var] -> Type -> Type
- piResultTy :: HasDebugCallStack => Type -> Type -> Type
- piResultTys :: HasDebugCallStack => 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
- getRuntimeRep_maybe :: HasDebugCallStack => Type -> Maybe Type
- getRuntimeRepFromKind_maybe :: HasDebugCallStack => Type -> Maybe Type
- mkCastTy :: Type -> Coercion -> Type
- mkCoercionTy :: Coercion -> Type
- splitCastTy_maybe :: Type -> Maybe (Type, Coercion)
- userTypeError_maybe :: Type -> Maybe Type
- pprUserTypeErrorTy :: Type -> SDoc
- coAxNthLHS :: CoAxiom br -> Int -> Type
- stripCoercionTy :: Type -> Coercion
- splitCoercionType_maybe :: Type -> Maybe (Type, Type)
- splitPiTysInvisible :: Type -> ([TyBinder], Type)
- filterOutInvisibleTypes :: TyCon -> [Type] -> [Type]
- partitionInvisibles :: TyCon -> (a -> Type) -> [a] -> ([a], [a])
- synTyConResKind :: TyCon -> Kind
- modifyJoinResTy :: Int -> (Type -> Type) -> Type -> Type
- setJoinResTy :: Int -> Type -> Type -> Type
- data TyCoMapper env m = TyCoMapper {
  - tcm_smart :: Bool
  - tcm_tyvar :: env -> TyVar -> m Type
  - tcm_covar :: env -> CoVar -> m Coercion
  - tcm_hole :: env -> CoercionHole -> m Coercion
  - tcm_tybinder :: env -> TyVar -> ArgFlag -> m (env, TyVar)
  }
- mapType :: Monad m => TyCoMapper env m -> env -> Type -> m Type
- mapCoercion :: Monad m => TyCoMapper env m -> env -> Coercion -> m Coercion
- newTyConInstRhs :: TyCon -> [Type] -> Type
- mkFamilyTyConApp :: TyCon -> [Type] -> Type
- isDictLikeTy :: Type -> Bool
- mkPrimEqPred :: Type -> Type -> Type
- mkReprPrimEqPred :: Type -> Type -> Type
- mkPrimEqPredRole :: Role -> Type -> Type -> PredType
- equalityTyCon :: Role -> TyCon
- mkHeteroPrimEqPred :: Kind -> Kind -> Type -> Type -> Type
- mkHeteroReprPrimEqPred :: Kind -> Kind -> Type -> Type -> Type
- mkClassPred :: Class -> [Type] -> PredType
- isClassPred :: PredType -> Bool
- isEqPred :: PredType -> Bool
- isNomEqPred :: PredType -> Bool
- isIPPred :: PredType -> Bool
- isIPPred_maybe :: Type -> Maybe (FastString, Type)
- isIPTyCon :: TyCon -> Bool
- isIPClass :: Class -> Bool
- isCTupleClass :: Class -> Bool
- data PredTree
  - = ClassPred Class [Type]
  - | EqPred EqRel Type Type
  - | 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
- sameVis :: ArgFlag -> ArgFlag -> Bool
- mkTyVarBinder :: ArgFlag -> Var -> TyVarBinder
- mkTyVarBinders :: ArgFlag -> [TyVar] -> [TyVarBinder]
- mkAnonBinder :: Type -> TyBinder
- isAnonTyBinder :: TyBinder -> Bool
- isNamedTyBinder :: TyBinder -> Bool
- binderVar :: TyVarBndr tv argf -> tv
- binderVars :: [TyVarBndr tv argf] -> [tv]
- binderKind :: TyVarBndr TyVar argf -> Kind
- binderArgFlag :: TyVarBndr tv argf -> argf
- tyBinderType :: TyBinder -> Type
- binderRelevantType_maybe :: TyBinder -> Maybe Type
- caseBinder :: TyBinder -> (TyVarBinder -> a) -> (Type -> a) -> a
- isVisibleArgFlag :: ArgFlag -> Bool
- isInvisibleArgFlag :: ArgFlag -> Bool
- isVisibleBinder :: TyBinder -> Bool
- isInvisibleBinder :: TyBinder -> Bool
- tyConBindersTyBinders :: [TyConBinder] -> [TyBinder]
- funTyCon :: TyCon
- isTyVarTy :: Type -> Bool
- isFunTy :: Type -> Bool
- isDictTy :: Type -> Bool
- isPredTy :: Type -> Bool
- isCoercionTy :: Type -> Bool
- isCoercionTy_maybe :: Type -> Maybe Coercion
- isCoercionType :: Type -> Bool
- isForAllTy :: Type -> Bool
- isPiTy :: Type -> Bool
- isTauTy :: Type -> Bool
- isFamFreeTy :: Type -> Bool
- isValidJoinPointType :: JoinArity -> Type -> Bool
- isLiftedType_maybe :: HasDebugCallStack => Type -> Maybe Bool
- isUnliftedType :: HasDebugCallStack => Type -> Bool
- isUnboxedTupleType :: Type -> Bool
- isUnboxedSumType :: Type -> Bool
- isAlgType :: Type -> Bool
- isDataFamilyAppType :: Type -> Bool
- isPrimitiveType :: Type -> Bool
- isStrictType :: HasDebugCallStack => Type -> Bool
- isRuntimeRepTy :: Type -> Bool
- isRuntimeRepVar :: TyVar -> Bool
- isRuntimeRepKindedTy :: Type -> Bool
- dropRuntimeRepArgs :: [Type] -> [Type]
- getRuntimeRep :: HasDebugCallStack => Type -> Type
- getRuntimeRepFromKind :: HasDebugCallStack => Type -> Type
- type Kind = Type
- typeKind :: HasDebugCallStack => Type -> Kind
- isTypeLevPoly :: Type -> Bool
- resultIsLevPoly :: Type -> Bool
- liftedTypeKind :: Kind
- tyCoFVsOfType :: Type -> FV
- tyCoFVsBndr :: TyVarBinder -> FV -> FV
- tyCoVarsOfType :: Type -> TyCoVarSet
- tyCoVarsOfTypes :: [Type] -> TyCoVarSet
- tyCoVarsOfTypeDSet :: Type -> DTyCoVarSet
- coVarsOfType :: Type -> CoVarSet
- coVarsOfTypes :: [Type] -> TyCoVarSet
- closeOverKinds :: TyVarSet -> TyVarSet
- closeOverKindsList :: [TyVar] -> [TyVar]
- noFreeVarsOfType :: Type -> Bool
- splitVisVarsOfType :: Type -> Pair TyCoVarSet
- splitVisVarsOfTypes :: [Type] -> Pair TyCoVarSet
- expandTypeSynonyms :: Type -> Type
- typeSize :: Type -> Int
- dVarSetElemsWellScoped :: DVarSet -> [Var]
- toposortTyVars :: [TyCoVar] -> [TyCoVar]
- tyCoVarsOfTypeWellScoped :: Type -> [TyVar]
- tyCoVarsOfTypesWellScoped :: [Type] -> [TyVar]
- eqType :: Type -> Type -> Bool
- eqTypeX :: RnEnv2 -> Type -> Type -> Bool
- eqTypes :: [Type] -> [Type] -> Bool
- nonDetCmpType :: Type -> Type -> Ordering
- nonDetCmpTypes :: [Type] -> [Type] -> Ordering
- nonDetCmpTypeX :: RnEnv2 -> Type -> Type -> Ordering
- nonDetCmpTypesX :: RnEnv2 -> [Type] -> [Type] -> Ordering
- nonDetCmpTc :: TyCon -> TyCon -> Ordering
- eqVarBndrs :: RnEnv2 -> [Var] -> [Var] -> Maybe RnEnv2
- seqType :: Type -> ()
- seqTypes :: [Type] -> ()
- coreView :: Type -> Maybe Type
- tcView :: Type -> Maybe Type
- tyConsOfType :: Type -> UniqSet TyCon
- type TvSubstEnv = TyVarEnv Type
- data TCvSubst = TCvSubst InScopeSet TvSubstEnv CvSubstEnv
- emptyTvSubstEnv :: TvSubstEnv
- emptyTCvSubst :: TCvSubst
- mkEmptyTCvSubst :: InScopeSet -> TCvSubst
- mkTCvSubst :: InScopeSet -> (TvSubstEnv, CvSubstEnv) -> TCvSubst
- zipTvSubst :: [TyVar] -> [Type] -> TCvSubst
- mkTvSubstPrs :: [(TyVar, Type)] -> TCvSubst
- notElemTCvSubst :: Var -> TCvSubst -> Bool
- getTvSubstEnv :: TCvSubst -> TvSubstEnv
- setTvSubstEnv :: TCvSubst -> TvSubstEnv -> TCvSubst
- zapTCvSubst :: TCvSubst -> TCvSubst
- getTCvInScope :: TCvSubst -> InScopeSet
- getTCvSubstRangeFVs :: TCvSubst -> VarSet
- extendTCvInScope :: TCvSubst -> Var -> TCvSubst
- extendTCvInScopeList :: TCvSubst -> [Var] -> TCvSubst
- extendTCvInScopeSet :: TCvSubst -> VarSet -> TCvSubst
- extendTCvSubst :: TCvSubst -> TyCoVar -> Type -> TCvSubst
- extendCvSubst :: TCvSubst -> CoVar -> Coercion -> TCvSubst
- extendTvSubst :: TCvSubst -> TyVar -> Type -> TCvSubst
- extendTvSubstBinderAndInScope :: TCvSubst -> TyBinder -> Type -> TCvSubst
- extendTvSubstList :: TCvSubst -> [Var] -> [Type] -> TCvSubst
- extendTvSubstAndInScope :: TCvSubst -> TyVar -> Type -> TCvSubst
- extendTvSubstWithClone :: TCvSubst -> TyVar -> TyVar -> TCvSubst
- isInScope :: Var -> TCvSubst -> Bool
- composeTCvSubstEnv :: InScopeSet -> (TvSubstEnv, CvSubstEnv) -> (TvSubstEnv, CvSubstEnv) -> (TvSubstEnv, CvSubstEnv)
- composeTCvSubst :: TCvSubst -> TCvSubst -> TCvSubst
- zipTyEnv :: [TyVar] -> [Type] -> TvSubstEnv
- zipCoEnv :: [CoVar] -> [Coercion] -> CvSubstEnv
- isEmptyTCvSubst :: TCvSubst -> Bool
- unionTCvSubst :: TCvSubst -> TCvSubst -> TCvSubst
- substTy :: HasCallStack => TCvSubst -> Type -> Type
- substTys :: HasCallStack => TCvSubst -> [Type] -> [Type]
- substTyWith :: HasCallStack => [TyVar] -> [Type] -> Type -> Type
- substTysWith :: [TyVar] -> [Type] -> [Type] -> [Type]
- substTheta :: HasCallStack => TCvSubst -> ThetaType -> ThetaType
- substTyAddInScope :: TCvSubst -> Type -> Type
- substTyUnchecked :: TCvSubst -> Type -> Type
- substTysUnchecked :: TCvSubst -> [Type] -> [Type]
- substThetaUnchecked :: TCvSubst -> ThetaType -> ThetaType
- substTyWithUnchecked :: [TyVar] -> [Type] -> Type -> Type
- substCoUnchecked :: TCvSubst -> Coercion -> Coercion
- substCoWithUnchecked :: [TyVar] -> [Type] -> Coercion -> Coercion
- substTyVarBndr :: HasCallStack => TCvSubst -> TyVar -> (TCvSubst, TyVar)
- substTyVar :: TCvSubst -> TyVar -> Type
- substTyVars :: TCvSubst -> [TyVar] -> [Type]
- cloneTyVarBndr :: TCvSubst -> TyVar -> Unique -> (TCvSubst, TyVar)
- cloneTyVarBndrs :: TCvSubst -> [TyVar] -> UniqSupply -> (TCvSubst, [TyVar])
- lookupTyVar :: TCvSubst -> TyVar -> Maybe Type
- pprType :: Type -> SDoc
- pprParendType :: Type -> SDoc
- pprPrecType :: TyPrec -> Type -> SDoc
- pprTypeApp :: TyCon -> [Type] -> SDoc
- pprTyThingCategory :: TyThing -> SDoc
- pprShortTyThing :: TyThing -> SDoc
- pprTvBndr :: TyVarBinder -> SDoc
- pprTvBndrs :: [TyVarBinder] -> SDoc
- pprForAll :: [TyVarBinder] -> SDoc
- pprUserForAll :: [TyVarBinder] -> SDoc
- pprSigmaType :: Type -> SDoc
- ppSuggestExplicitKinds :: 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
- pprTyVar :: TyVar -> SDoc
- pprTyVars :: [TyVar] -> SDoc
- tidyType :: TidyEnv -> Type -> Type
- tidyTypes :: TidyEnv -> [Type] -> [Type]
- tidyOpenType :: TidyEnv -> Type -> (TidyEnv, Type)
- tidyOpenTypes :: TidyEnv -> [Type] -> (TidyEnv, [Type])
- tidyOpenKind :: TidyEnv -> Kind -> (TidyEnv, Kind)
- tidyTyCoVarBndr :: TidyEnv -> TyCoVar -> (TidyEnv, TyCoVar)
- tidyTyCoVarBndrs :: TidyEnv -> [TyCoVar] -> (TidyEnv, [TyCoVar])
- tidyFreeTyCoVars :: TidyEnv -> [TyCoVar] -> TidyEnv
- tidyOpenTyCoVar :: TidyEnv -> TyCoVar -> (TidyEnv, TyCoVar)
- tidyOpenTyCoVars :: TidyEnv -> [TyCoVar] -> (TidyEnv, [TyCoVar])
- tidyTyVarOcc :: TidyEnv -> TyVar -> TyVar
- tidyTopType :: Type -> Type
- tidyKind :: TidyEnv -> Kind -> Kind
- tidyTyVarBinder :: TidyEnv -> TyVarBndr TyVar vis -> (TidyEnv, TyVarBndr TyVar vis)
- tidyTyVarBinders :: TidyEnv -> [TyVarBndr TyVar vis] -> (TidyEnv, [TyVarBndr TyVar vis])

# 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 #) 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 #

A global typecheckable-thing, essentially anything that has a name. Not to be confused with a `TcTyThing`, which is also a typecheckable thing but in the *local* context. See `TcEnv` for how to retrieve a `TyThing` given a `Name`.

Constructors

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

Instances

Outputable TyThing # |
Instance details Defined in TyCoRep Methods ppr :: TyThing -> SDoc # pprPrec :: Rational -> TyThing -> SDoc #
NamedThing TyThing # |
Instance details Defined in TyCoRep Methods getOccName :: TyThing -> OccName # getName :: TyThing -> Name #

data Type #

Instances

Data Type # |
Instance details Defined in TyCoRep Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Type -> c Type Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Type Source # toConstr :: Type -> Constr Source # dataTypeOf :: Type -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Type) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Type) Source # gmapT :: (forall b. Data b => b -> b) -> Type -> Type Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Type -> r Source # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Type -> r Source # gmapQ :: (forall d. Data d => d -> u) -> Type -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> Type -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Type -> m Type Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Type -> m Type Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Type -> m Type Source #
Outputable Type # |
Instance details Defined in TyCoRep Methods ppr :: Type -> SDoc # pprPrec :: Rational -> Type -> SDoc #

data ArgFlag #

Argument Flag

Is something required to appear in source Haskell (`Required`), permitted by request (`Specified`) (visible type application), or prohibited entirely from appearing in source Haskell (`Inferred`)? See Note [TyVarBndrs, TyVarBinders, TyConBinders, and visibility] in TyCoRep

Constructors

Required |
Specified |
Inferred |

Instances

Eq ArgFlag # |
Instance details Defined in Var Methods (==) :: ArgFlag -> ArgFlag -> Bool # (/=) :: ArgFlag -> ArgFlag -> Bool #
Data ArgFlag # |
Instance details Defined in Var Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ArgFlag -> c ArgFlag Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c ArgFlag Source # toConstr :: ArgFlag -> Constr Source # dataTypeOf :: ArgFlag -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c ArgFlag) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ArgFlag) Source # gmapT :: (forall b. Data b => b -> b) -> ArgFlag -> ArgFlag Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ArgFlag -> r Source # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ArgFlag -> r Source # gmapQ :: (forall d. Data d => d -> u) -> ArgFlag -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> ArgFlag -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> ArgFlag -> m ArgFlag Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ArgFlag -> m ArgFlag Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ArgFlag -> m ArgFlag Source #
Outputable ArgFlag # |
Instance details Defined in Var Methods ppr :: ArgFlag -> SDoc # pprPrec :: Rational -> ArgFlag -> SDoc #
Binary ArgFlag # |
Instance details Defined in Var Methods put_ :: BinHandle -> ArgFlag -> IO () # put :: BinHandle -> ArgFlag -> IO (Bin ArgFlag) # get :: BinHandle -> IO ArgFlag #
Outputable tv => Outputable (TyVarBndr tv ArgFlag) # |
Instance details Defined in Var Methods ppr :: TyVarBndr tv ArgFlag -> SDoc # pprPrec :: Rational -> TyVarBndr tv ArgFlag -> SDoc #

type KindOrType = Type #

The key representation of types within the compiler

type PredType = Type #

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] #

A collection of `PredType`s

data Var #

Variable

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

Instances

Eq Var # |
Instance details Defined in Var Methods (==) :: Var -> Var -> Bool # (/=) :: Var -> Var -> Bool #
Data Var # |
Instance details Defined in Var Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Var -> c Var Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Var Source # toConstr :: Var -> Constr Source # dataTypeOf :: Var -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Var) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Var) Source # gmapT :: (forall b. Data b => b -> b) -> Var -> Var Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Var -> r Source # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Var -> r Source # gmapQ :: (forall d. Data d => d -> u) -> Var -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> Var -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Var -> m Var Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Var -> m Var Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Var -> m Var Source #
Ord Var # |
Instance details Defined in Var Methods compare :: Var -> Var -> Ordering # (<) :: Var -> Var -> Bool # (<=) :: Var -> Var -> Bool # (>) :: Var -> Var -> Bool # (>=) :: Var -> Var -> Bool # max :: Var -> Var -> Var # min :: Var -> Var -> Var #
OutputableBndr Var # |
Instance details Defined in PprCore Methods pprBndr :: BindingSite -> Var -> SDoc # pprPrefixOcc :: Var -> SDoc # pprInfixOcc :: Var -> SDoc # bndrIsJoin_maybe :: Var -> Maybe Int #
Outputable Var # |
Instance details Defined in Var Methods ppr :: Var -> SDoc # pprPrec :: Rational -> Var -> SDoc #
Uniquable Var # |
Instance details Defined in Var Methods getUnique :: Var -> Unique #
HasOccName Var # |
Instance details Defined in Var Methods occName :: Var -> OccName #
NamedThing Var # |
Instance details Defined in Var Methods getOccName :: Var -> OccName # getName :: Var -> Name #

type TyVar = Var #

Type or kind Variable

isTyVar :: Var -> Bool #

type TyCoVar = Id #

Type or Coercion Variable

data TyBinder #

A `TyBinder` represents an argument to a function. TyBinders can be dependent (`Named`) or nondependent (`Anon`). They may also be visible or not. See Note [TyBinders]

Instances

Data TyBinder # |
Instance details Defined in TyCoRep Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> TyBinder -> c TyBinder Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c TyBinder Source # toConstr :: TyBinder -> Constr Source # dataTypeOf :: TyBinder -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c TyBinder) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TyBinder) Source # gmapT :: (forall b. Data b => b -> b) -> TyBinder -> TyBinder Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TyBinder -> r Source # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TyBinder -> r Source # gmapQ :: (forall d. Data d => d -> u) -> TyBinder -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> TyBinder -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> TyBinder -> m TyBinder Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> TyBinder -> m TyBinder Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> TyBinder -> m TyBinder Source #
Outputable TyBinder # |
Instance details Defined in TyCoRep Methods ppr :: TyBinder -> SDoc # pprPrec :: Rational -> TyBinder -> SDoc #

type TyVarBinder = TyVarBndr TyVar ArgFlag #

Type Variable Binder

A `TyVarBinder` is the binder of a ForAllTy It's convenient to define this synonym here rather its natural home in TyCoRep, because it's used in DataCon.hs-boot

## Constructing and deconstructing types

mkTyVarTy :: TyVar -> Type #

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

getTyVar :: String -> Type -> TyVar #

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 #

Attempts to obtain the type variable underlying a `Type`

repGetTyVar_maybe :: Type -> Maybe TyVar #

Attempts to obtain the type variable underlying a `Type`, without any expansion

getCastedTyVar_maybe :: Type -> Maybe (TyVar, CoercionN) #

If the type is a tyvar, possibly under a cast, returns it, along with the coercion. Thus, the co is :: kind tv ~N kind type

tyVarKind :: TyVar -> Kind #

mkAppTy :: Type -> Type -> Type #

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

mkAppTys :: Type -> [Type] -> Type #

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

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

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

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.

repSplitAppTys :: HasDebugCallStack => Type -> (Type, [Type]) #

Like `splitAppTys`, but doesn't look through type synonyms

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

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 :: HasDebugCallStack => Type -> Maybe (Type, Type) #

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

tcRepSplitAppTy_maybe :: Type -> Maybe (Type, Type) #

Does the AppTy split as in `tcSplitAppTy_maybe`, but assumes that any coreView stuff is already done. Refuses to look through (c => t)

mkFunTy :: Type -> Type -> Type infixr 3 #

Make an arrow type

mkFunTys :: [Type] -> Type -> Type #

Make nested arrow types

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

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) #

Attempts to extract the argument and result types from a type

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

funResultTy :: Type -> Type #

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

funArgTy :: Type -> Type #

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

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

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 #

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

tyConAppTyCon_maybe :: Type -> Maybe TyCon #

The same as `fst . splitTyConApp`

tyConAppTyConPicky_maybe :: Type -> Maybe TyCon #

Retrieve the tycon heading this type, if there is one. Does not look through synonyms.

tyConAppArgs_maybe :: Type -> Maybe [Type] #

The same as `snd . splitTyConApp`

tyConAppTyCon :: Type -> TyCon #

tyConAppArgs :: Type -> [Type] #

splitTyConApp_maybe :: HasDebugCallStack => Type -> Maybe (TyCon, [Type]) #

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]) #

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 #

nextRole :: Type -> Role #

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!

tcRepSplitTyConApp_maybe :: HasCallStack => Type -> Maybe (TyCon, [Type]) #

Like `tcSplitTyConApp_maybe` but doesn't look through type synonyms.

tcSplitTyConApp_maybe :: HasCallStack => Type -> Maybe (TyCon, [Type]) #

Split a type constructor application into its type constructor and applied types. Note that this may fail in the case of a `FunTy` with an argument of unknown kind `FunTy` (e.g. `FunTy (a :: k) Int`. since the kind of `a` isn't of the form `TYPE rep`). Consequently, you may need to zonk your type before using this function.

If you only need the `TyCon`, consider using `tcTyConAppTyCon_maybe`.

splitListTyConApp_maybe :: Type -> Maybe Type #

Attempts to tease a list type apart and gives the type of the elements if successful (looks through type synonyms)

repSplitTyConApp_maybe :: HasDebugCallStack => Type -> Maybe (TyCon, [Type]) #

Like `splitTyConApp_maybe`, but doesn't look through synonyms. This assumes the synonyms have already been dealt with.

mkForAllTy :: TyVar -> ArgFlag -> Type -> Type #

mkForAllTys :: [TyVarBinder] -> Type -> Type #

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

mkInvForAllTys :: [TyVar] -> Type -> Type #

Like mkForAllTys, but assumes all variables are dependent and Inferred, a common case

mkSpecForAllTys :: [TyVar] -> Type -> Type #

Like mkForAllTys, but assumes all variables are dependent and specified, a common case

mkVisForAllTys :: [TyVar] -> Type -> Type #

Like mkForAllTys, but assumes all variables are dependent and visible

mkInvForAllTy :: TyVar -> Type -> Type #

Make a dependent forall over an Inferred (as opposed to Specified) variable

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

Take a ForAllTy apart, returning the list of tyvars and the result type. This always succeeds, even if it returns only an empty list. Note that the result type returned may have free variables that were bound by a forall.

splitForAllTyVarBndrs :: Type -> ([TyVarBinder], Type) #

Like `splitPiTys` but split off only named binders.

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

Attempts to take a forall type apart, but only if it's a proper forall, with a named binder

splitForAllTy :: Type -> (TyVar, Type) #

Take a forall type apart, or panics if that is not possible.

splitPiTy_maybe :: Type -> Maybe (TyBinder, Type) #

Attempts to take a forall type apart; works with proper foralls and functions

splitPiTy :: Type -> (TyBinder, Type) #

Takes a forall type apart, or panics

splitPiTys :: Type -> ([TyBinder], Type) #

Split off all TyBinders to a type, splitting both proper foralls and functions

mkPiTy :: TyBinder -> Type -> Type #

mkPiTys :: [TyBinder] -> Type -> Type #

mkTyConBindersPreferAnon :: [TyVar] -> Type -> [TyConBinder] #

Given a list of type-level vars and a result kind, makes TyBinders, preferring anonymous binders if the variable is, in fact, not dependent. e.g. mkTyConBindersPreferAnon (k:*),(b:k),(c:k) We want (k:*) Named, (a;k) Anon, (c:k) Anon

All binders are visible.

mkLamType :: Var -> Type -> Type #

Makes a `(->)` type or an implicit forall type, depending on whether it is given a type variable or a term variable. This is used, for example, when producing the type of a lambda. Always uses Inferred binders.

mkLamTypes :: [Var] -> Type -> Type #

`mkLamType` for multiple type or value arguments

piResultTy :: HasDebugCallStack => Type -> Type -> Type #

piResultTys :: HasDebugCallStack => Type -> [Type] -> Type #

(piResultTys f_ty [ty1, .., tyn]) gives the type of (f ty1 .. tyn) where f :: f_ty `piResultTys` is interesting because: 1. `f_ty` may have more for-alls than there are args 2. Less obviously, it may have fewer for-alls For case 2. think of: piResultTys (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.

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

dropForAlls :: Type -> Type #

Drops all ForAllTys

mkNumLitTy :: Integer -> Type #

isNumLitTy :: Type -> Maybe Integer #

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

mkStrLitTy :: FastString -> Type #

isStrLitTy :: Type -> Maybe FastString #

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

getRuntimeRep_maybe :: HasDebugCallStack => Type -> Maybe Type #

Extract the RuntimeRep classifier of a type. For instance, `getRuntimeRep_maybe Int = LiftedRep`. Returns `Nothing` if this is not possible.

getRuntimeRepFromKind_maybe :: HasDebugCallStack => Type -> Maybe Type #

Extract the RuntimeRep classifier of a type from its kind. For example, `getRuntimeRepFromKind * = LiftedRep`; Returns `Nothing` if this is not possible.

mkCastTy :: Type -> Coercion -> Type #

Make a `CastTy`. The Coercion must be nominal. Checks the Coercion for reflexivity, dropping it if it's reflexive. See Note [No reflexive casts in types]

mkCoercionTy :: Coercion -> Type #

splitCastTy_maybe :: Type -> Maybe (Type, Coercion) #

userTypeError_maybe :: Type -> Maybe Type #

Is this type a custom user error? If so, give us the kind and the error message.

pprUserTypeErrorTy :: Type -> SDoc #

Render a type corresponding to a user type error into a SDoc.

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

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

stripCoercionTy :: Type -> Coercion #

splitCoercionType_maybe :: Type -> Maybe (Type, Type) #

Try to split up a coercion type into the types that it coerces

splitPiTysInvisible :: Type -> ([TyBinder], Type) #

filterOutInvisibleTypes :: TyCon -> [Type] -> [Type] #

Given a tycon and its arguments, filters out any invisible arguments

partitionInvisibles :: TyCon -> (a -> Type) -> [a] -> ([a], [a]) #

Given a tycon and a list of things (which correspond to arguments), partitions the things into Inferred or Specified ones and Required ones The callback function is necessary for this scenario:

    T :: forall k. k -> k
    partitionInvisibles T [forall m. m -> m -> m, S, R, Q]

After substituting, we get

    T (forall m. m -> m -> m) :: (forall m. m -> m -> m) -> forall n. n -> n -> n

Thus, the first argument is invisible, `S` is visible, `R` is invisible again, and `Q` is visible.

If you're absolutely sure that your tycon's kind doesn't end in a variable, it's OK if the callback function panics, as that's the only time it's consulted.

synTyConResKind :: TyCon -> Kind #

Find the result `Kind` of a type synonym, after applying it to its `arity` number of type variables Actually this function works fine on data types too, but they'd always return `*`, so we never need to ask

modifyJoinResTy :: Int -> (Type -> Type) -> Type -> Type #

setJoinResTy :: Int -> Type -> Type -> Type #

data TyCoMapper env m #

This describes how a "map" operation over a type/coercion should behave

Constructors

TyCoMapper |
Fields tcm_smart :: Bool Should the new type be created with smart constructors? tcm_tyvar :: env -> TyVar -> m Type tcm_covar :: env -> CoVar -> m Coercion tcm_hole :: env -> CoercionHole -> m Coercion What to do with coercion holes. See Note [Coercion holes] in TyCoRep. tcm_tybinder :: env -> TyVar -> ArgFlag -> m (env, TyVar) The returned env is used in the extended scope

mapType :: Monad m => TyCoMapper env m -> env -> Type -> m Type #

mapCoercion :: Monad m => TyCoMapper env m -> env -> Coercion -> m Coercion #

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

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 #

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 #

mkPrimEqPred :: Type -> Type -> Type #

Creates a primitive type equality predicate. Invariant: the types are not Coercions

mkReprPrimEqPred :: Type -> Type -> Type #

mkPrimEqPredRole :: Role -> Type -> Type -> PredType #

Makes a lifted equality predicate at the given role

equalityTyCon :: Role -> TyCon #

mkHeteroPrimEqPred :: Kind -> Kind -> Type -> Type -> Type #

Creates a primite type equality predicate with explicit kinds

mkHeteroReprPrimEqPred :: Kind -> Kind -> Type -> Type -> Type #

Creates a primitive representational type equality predicate with explicit kinds

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

isClassPred :: PredType -> Bool #

isEqPred :: PredType -> Bool #

isNomEqPred :: PredType -> Bool #

isIPPred :: PredType -> Bool #

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

isIPTyCon :: TyCon -> Bool #

isIPClass :: Class -> Bool #

isCTupleClass :: Class -> Bool #

data PredTree #

Constructors

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

data EqRel #

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 # |
Instance details Defined in Type Methods (==) :: EqRel -> EqRel -> Bool # (/=) :: EqRel -> EqRel -> Bool #
Ord EqRel # |
Instance details Defined in Type Methods compare :: EqRel -> EqRel -> Ordering # (<) :: EqRel -> EqRel -> Bool # (<=) :: EqRel -> EqRel -> Bool # (>) :: EqRel -> EqRel -> Bool # (>=) :: EqRel -> EqRel -> Bool # max :: EqRel -> EqRel -> EqRel # min :: EqRel -> EqRel -> EqRel #
Outputable EqRel # |
Instance details Defined in Type Methods ppr :: EqRel -> SDoc # pprPrec :: Rational -> EqRel -> SDoc #

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 #

Get the equality relation relevant for a pred type.

## Binders

sameVis :: ArgFlag -> ArgFlag -> Bool #

Do these denote the same level of visibility? `Required` arguments are visible, others are not. So this function equates `Specified` and `Inferred`. Used for printing.

mkTyVarBinder :: ArgFlag -> Var -> TyVarBinder #

Make a named binder

mkTyVarBinders :: ArgFlag -> [TyVar] -> [TyVarBinder] #

Make many named binders

mkAnonBinder :: Type -> TyBinder #

Make an anonymous binder

isAnonTyBinder :: TyBinder -> Bool #

Does this binder bind a variable that is not erased? Returns `True` for anonymous binders.

isNamedTyBinder :: TyBinder -> Bool #

binderVar :: TyVarBndr tv argf -> tv #

binderVars :: [TyVarBndr tv argf] -> [tv] #

binderKind :: TyVarBndr TyVar argf -> Kind #

binderArgFlag :: TyVarBndr tv argf -> argf #

tyBinderType :: TyBinder -> Type #

binderRelevantType_maybe :: TyBinder -> Maybe Type #

Extract a relevant type, if there is one.

caseBinder #

Arguments

:: TyBinder | binder to scrutinize
-> (TyVarBinder -> a) | named case
-> (Type -> a) | anonymous case
-> a |

Like `maybe`, but for binders.

isVisibleArgFlag :: ArgFlag -> Bool #

Does this `ArgFlag` classify an argument that is written in Haskell?

isInvisibleArgFlag :: ArgFlag -> Bool #

Does this `ArgFlag` classify an argument that is not written in Haskell?

isVisibleBinder :: TyBinder -> Bool #

Does this binder bind a visible argument?

isInvisibleBinder :: TyBinder -> Bool #

Does this binder bind an invisible argument?

tyConBindersTyBinders :: [TyConBinder] -> [TyBinder] #

## Common type constructors

funTyCon :: TyCon #

The `(->)` type constructor.

    (->) :: forall (rep1 :: RuntimeRep) (rep2 :: RuntimeRep).
            TYPE rep1 -> TYPE rep2 -> *

## Predicates on types

isTyVarTy :: Type -> Bool #

isFunTy :: Type -> Bool #

isDictTy :: Type -> Bool #

isPredTy :: Type -> Bool #

Is the type suitable to classify a given/wanted in the typechecker?

isCoercionTy :: Type -> Bool #

isCoercionTy_maybe :: Type -> Maybe Coercion #

isCoercionType :: Type -> Bool #

Does this type classify a core (unlifted) Coercion? At either role nominal or representational (t1 ~ t2)

isForAllTy :: Type -> Bool #

Checks whether this is a proper forall (with a named binder)

isPiTy :: Type -> Bool #

Is this a function or forall?

isTauTy :: Type -> Bool #

isFamFreeTy :: Type -> Bool #

isValidJoinPointType :: JoinArity -> Type -> Bool #

Determine whether a type could be the type of a join point of given total arity, according to the polymorphism rule. A join point cannot be polymorphic in its return type, since given join j `a` b x y z = e1 in e2, the types of e1 and e2 must be the same, and a and b are not in scope for e2. (See Note [The polymorphism rule of join points] in CoreSyn.) Returns False also if the type simply doesn't have enough arguments.

Note that we need to know how many arguments (type *and* value) the putative join point takes; for instance, if j :: forall a. a -> Int then j could be a binary join point returning an Int, but it could *not* be a unary join point returning a -> Int.

TODO: See Note [Excess polymorphism and join points]

isLiftedType_maybe :: HasDebugCallStack => Type -> Maybe Bool #

Returns Just True if this type is surely lifted, Just False if it is surely unlifted, Nothing if we can't be sure (i.e., it is levity polymorphic), and panics if the kind does not have the shape TYPE r.

isUnliftedType :: HasDebugCallStack => Type -> Bool #

See Type for what an unlifted type is. Panics on levity polymorphic types.

isUnboxedTupleType :: Type -> Bool #

isUnboxedSumType :: Type -> Bool #

isAlgType :: Type -> Bool #

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

isDataFamilyAppType :: Type -> Bool #

Check whether a type is a data family type

isPrimitiveType :: Type -> Bool #

Returns true of types that are opaque to Haskell.

isStrictType :: HasDebugCallStack => Type -> Bool #

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`. Panics on levity-polymorphic types.

isRuntimeRepTy :: Type -> Bool #

Is this the type `RuntimeRep`?

isRuntimeRepVar :: TyVar -> Bool #

Is a tyvar of type `RuntimeRep`?

isRuntimeRepKindedTy :: Type -> Bool #

Is this a type of kind RuntimeRep? (e.g. LiftedRep)

dropRuntimeRepArgs :: [Type] -> [Type] #

Drops prefix of RuntimeRep constructors in `TyConApp`s. Useful for e.g. dropping 'LiftedRep arguments of unboxed tuple TyCon applications:

dropRuntimeRepArgs [ 'LiftedRep, 'IntRep , String, Int]

getRuntimeRep :: HasDebugCallStack => Type -> Type #

Extract the RuntimeRep classifier of a type. For instance, `getRuntimeRep_maybe Int = LiftedRep`. Panics if this is not possible.

getRuntimeRepFromKind :: HasDebugCallStack => Type -> Type #

Extract the RuntimeRep classifier of a type from its kind. For example, `getRuntimeRepFromKind * = LiftedRep`; Panics if this is not possible.

# Main data types representing Kinds

type Kind = Type #

The key type representing kinds in the compiler.

## Finding the kind of a type

typeKind :: HasDebugCallStack => Type -> Kind #

isTypeLevPoly :: Type -> Bool #

Returns True if a type is levity polymorphic. Should be the same as (isKindLevPoly . typeKind) but much faster. Precondition: The type has kind (TYPE blah)

resultIsLevPoly :: Type -> Bool #

Looking past all pi-types, is the end result potentially levity polymorphic? Example: True for (forall r (a :: TYPE r). String -> a) Example: False for (forall r1 r2 (a :: TYPE r1) (b :: TYPE r2). a -> b -> Type)

## Common Kind

liftedTypeKind :: Kind #

# Type free variables

tyCoFVsOfType :: Type -> FV #

The worker for `tyCoFVsOfType` and `tyCoFVsOfTypeList`. The previous implementation used `unionVarSet` which is O(n+m) and can make the function quadratic. It's exported, so that it can be composed with other functions that compute free variables. See Note [FV naming conventions] in FV.

Eta-expanded because that makes it run faster (apparently) See Note [FV eta expansion] in FV for explanation.

tyCoFVsBndr :: TyVarBinder -> FV -> FV #

tyCoVarsOfType :: Type -> TyCoVarSet #

Returns free variables of a type, including kind variables as a non-deterministic set. For type synonyms it does not expand the synonym.

tyCoVarsOfTypes :: [Type] -> TyCoVarSet #

Returns free variables of types, including kind variables as a non-deterministic set. For type synonyms it does not expand the synonym.

tyCoVarsOfTypeDSet :: Type -> DTyCoVarSet #

`tyCoFVsOfType` that returns free variables of a type in a deterministic set. For explanation of why using `VarSet` is not deterministic see Note [Deterministic FV] in FV.

coVarsOfType :: Type -> CoVarSet #

coVarsOfTypes :: [Type] -> TyCoVarSet #

closeOverKinds :: TyVarSet -> TyVarSet #

Add the kind variables free in the kinds of the tyvars in the given set. Returns a non-deterministic set.

closeOverKindsList :: [TyVar] -> [TyVar] #

Add the kind variables free in the kinds of the tyvars in the given set. Returns a deterministically ordered list.

noFreeVarsOfType :: Type -> Bool #

Returns True if this type has no free variables. Should be the same as isEmptyVarSet . tyCoVarsOfType, but faster in the non-forall case.

splitVisVarsOfType :: Type -> Pair TyCoVarSet #

Retrieve the free variables in this type, splitting them based on whether they are used visibly or invisibly. Invisible ones come first.

splitVisVarsOfTypes :: [Type] -> Pair TyCoVarSet #

expandTypeSynonyms :: Type -> Type #

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.

`expandTypeSynonyms` only expands out type synonyms mentioned in the type, not in the kinds of any TyCon or TyVar mentioned in the type.

Keep this synchronized with `synonymTyConsOfType`

typeSize :: Type -> Int #

# Well-scoped lists of variables

dVarSetElemsWellScoped :: DVarSet -> [Var] #

Extract a well-scoped list of variables from a deterministic set of variables. The result is deterministic. NB: There used to exist varSetElemsWellScoped :: VarSet -> [Var] which took a non-deterministic set and produced a non-deterministic well-scoped list. If you care about the list being well-scoped you also most likely care about it being in deterministic order.

toposortTyVars :: [TyCoVar] -> [TyCoVar] #

Do a topological sort on a list of tyvars, so that binders occur before occurrences E.g. given [ a::k, k::*, b::k ] it'll return a well-scoped list [ k::*, a::k, b::k ]

This is a deterministic sorting operation (that is, doesn't depend on Uniques).

tyCoVarsOfTypeWellScoped :: Type -> [TyVar] #

Get the free vars of a type in scoped order

tyCoVarsOfTypesWellScoped :: [Type] -> [TyVar] #

Get the free vars of types in scoped order

# Type comparison

eqType :: Type -> Type -> Bool #

Type equality on source types. Does not look through `newtypes` or `PredType`s, but it does look through type synonyms. This first checks that the kinds of the types are equal and then checks whether the types are equal, ignoring casts and coercions. (The kind check is a recursive call, but since all kinds have type `Type`, there is no need to check the types of kinds.) See also Note [Non-trivial definitional equality] in TyCoRep.

eqTypeX :: RnEnv2 -> Type -> Type -> Bool #

Compare types with respect to a (presumably) non-empty `RnEnv2`.

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

Type equality on lists of types, looking through type synonyms but not newtypes.

nonDetCmpType :: Type -> Type -> Ordering #

nonDetCmpTypes :: [Type] -> [Type] -> Ordering #

nonDetCmpTypeX :: RnEnv2 -> Type -> Type -> Ordering #

nonDetCmpTypesX :: RnEnv2 -> [Type] -> [Type] -> Ordering #

nonDetCmpTc :: TyCon -> TyCon -> Ordering #

Compare two `TyCon`s. NB: This should never see the "star synonyms", as recognized by Kind.isStarKindSynonymTyCon. See Note [Kind Constraint and kind *] in Kind. See Note [nonDetCmpType nondeterminism]

eqVarBndrs :: RnEnv2 -> [Var] -> [Var] -> Maybe RnEnv2 #

# Forcing evaluation of types

seqType :: Type -> () #

seqTypes :: [Type] -> () #

# Other views onto Types

coreView :: Type -> Maybe Type #

This function Strips off the top layer only of a type synonym application (if any) its underlying representation type. Returns Nothing if there is nothing to look through. This function considers `Constraint` to be a synonym of `TYPE LiftedRep`.

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 #

Gives the typechecker view of a type. This unwraps synonyms but leaves `Constraint` alone. c.f. coreView, which turns Constraint into TYPE LiftedRep. Returns Nothing if no unwrapping happens. See also Note [coreView vs tcView] in Type.

tyConsOfType :: Type -> UniqSet TyCon #

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

# Main type substitution data types

type TvSubstEnv = TyVarEnv Type #

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

data TCvSubst #

Type & coercion substitution

The following invariants must hold of a `TCvSubst`:

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 reach a fixed point.

Constructors

TCvSubst InScopeSet TvSubstEnv CvSubstEnv |

Instances

Outputable TCvSubst # |
Instance details Defined in TyCoRep Methods ppr :: TCvSubst -> SDoc # pprPrec :: Rational -> TCvSubst -> SDoc #

## Manipulating type substitutions

emptyTvSubstEnv :: TvSubstEnv #

emptyTCvSubst :: TCvSubst #

mkEmptyTCvSubst :: InScopeSet -> TCvSubst #

mkTCvSubst :: InScopeSet -> (TvSubstEnv, CvSubstEnv) -> TCvSubst #

zipTvSubst :: [TyVar] -> [Type] -> TCvSubst #

Generates the in-scope set for the `TCvSubst` from the types in the incoming environment. No CoVars, please!

mkTvSubstPrs :: [(TyVar, Type)] -> TCvSubst #

Generates the in-scope set for the `TCvSubst` from the types in the incoming environment. No CoVars, please!

notElemTCvSubst :: Var -> TCvSubst -> Bool #

getTvSubstEnv :: TCvSubst -> TvSubstEnv #

setTvSubstEnv :: TCvSubst -> TvSubstEnv -> TCvSubst #

zapTCvSubst :: TCvSubst -> TCvSubst #

getTCvInScope :: TCvSubst -> InScopeSet #

getTCvSubstRangeFVs :: TCvSubst -> VarSet #

Returns the free variables of the types in the range of a substitution as a non-deterministic set.

extendTCvInScope :: TCvSubst -> Var -> TCvSubst #

extendTCvInScopeList :: TCvSubst -> [Var] -> TCvSubst #

extendTCvInScopeSet :: TCvSubst -> VarSet -> TCvSubst #

extendTCvSubst :: TCvSubst -> TyCoVar -> Type -> TCvSubst #

extendCvSubst :: TCvSubst -> CoVar -> Coercion -> TCvSubst #

extendTvSubst :: TCvSubst -> TyVar -> Type -> TCvSubst #

extendTvSubstBinderAndInScope :: TCvSubst -> TyBinder -> Type -> TCvSubst #

extendTvSubstList :: TCvSubst -> [Var] -> [Type] -> TCvSubst #

extendTvSubstAndInScope :: TCvSubst -> TyVar -> Type -> TCvSubst #

extendTvSubstWithClone :: TCvSubst -> TyVar -> TyVar -> TCvSubst #

isInScope :: Var -> TCvSubst -> Bool #

composeTCvSubstEnv :: InScopeSet -> (TvSubstEnv, CvSubstEnv) -> (TvSubstEnv, CvSubstEnv) -> (TvSubstEnv, CvSubstEnv) #

`(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`

composeTCvSubst :: TCvSubst -> TCvSubst -> TCvSubst #

Composes two substitutions, applying the second one provided first, like in function composition.

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

zipCoEnv :: [CoVar] -> [Coercion] -> CvSubstEnv #

isEmptyTCvSubst :: TCvSubst -> Bool #

unionTCvSubst :: TCvSubst -> TCvSubst -> TCvSubst #

## Performing substitution on types and kinds

substTy :: HasCallStack => TCvSubst -> Type -> Type #

Substitute within a `Type` The substitution has to satisfy the invariants described in Note [The substitution invariant].

substTys :: HasCallStack => TCvSubst -> [Type] -> [Type] #

Substitute within several `Type`s The substitution has to satisfy the invariants described in Note [The substitution invariant].

substTyWith :: HasCallStack => [TyVar] -> [Type] -> Type -> Type #

Type substitution, see `zipTvSubst`

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

Type substitution, see `zipTvSubst`

substTheta :: HasCallStack => TCvSubst -> ThetaType -> ThetaType #

Substitute within a `ThetaType` The substitution has to satisfy the invariants described in Note [The substitution invariant].

substTyAddInScope :: TCvSubst -> Type -> Type #

Substitute within a `Type` after adding the free variables of the type to the in-scope set. This is useful for the case when the free variables aren't already in the in-scope set or easily available. See also Note [The substitution invariant].

substTyUnchecked :: TCvSubst -> Type -> Type #

Substitute within a `Type` disabling the sanity checks. The problems that the sanity checks in substTy catch are described in Note [The substitution invariant]. The goal of #11371 is to migrate all the calls of substTyUnchecked to substTy and remove this function. Please don't use in new code.

substTysUnchecked :: TCvSubst -> [Type] -> [Type] #

Substitute within several `Type`s disabling the sanity checks. The problems that the sanity checks in substTys catch are described in Note [The substitution invariant]. The goal of #11371 is to migrate all the calls of substTysUnchecked to substTys and remove this function. Please don't use in new code.

substThetaUnchecked :: TCvSubst -> ThetaType -> ThetaType #

Substitute within a `ThetaType` disabling the sanity checks. The problems that the sanity checks in substTys catch are described in Note [The substitution invariant]. The goal of #11371 is to migrate all the calls of substThetaUnchecked to substTheta and remove this function. Please don't use in new code.

substTyWithUnchecked :: [TyVar] -> [Type] -> Type -> Type #

Type substitution, see `zipTvSubst`. Disables sanity checks. The problems that the sanity checks in substTy catch are described in Note [The substitution invariant]. The goal of #11371 is to migrate all the calls of substTyUnchecked to substTy and remove this function. Please don't use in new code.

substCoUnchecked :: TCvSubst -> Coercion -> Coercion #

Substitute within a `Coercion` disabling sanity checks. The problems that the sanity checks in substCo catch are described in Note [The substitution invariant]. The goal of #11371 is to migrate all the calls of substCoUnchecked to substCo and remove this function. Please don't use in new code.

substCoWithUnchecked :: [TyVar] -> [Type] -> Coercion -> Coercion #

Coercion substitution, see `zipTvSubst`. Disables sanity checks. The problems that the sanity checks in substCo catch are described in Note [The substitution invariant]. The goal of #11371 is to migrate all the calls of substCoUnchecked to substCo and remove this function. Please don't use in new code.

substTyVarBndr :: HasCallStack => TCvSubst -> TyVar -> (TCvSubst, TyVar) #

substTyVar :: TCvSubst -> TyVar -> Type #

substTyVars :: TCvSubst -> [TyVar] -> [Type] #

cloneTyVarBndr :: TCvSubst -> TyVar -> Unique -> (TCvSubst, TyVar) #

cloneTyVarBndrs :: TCvSubst -> [TyVar] -> UniqSupply -> (TCvSubst, [TyVar]) #

lookupTyVar :: TCvSubst -> TyVar -> Maybe Type #

# Pretty-printing

pprType :: Type -> SDoc #

pprParendType :: Type -> SDoc #

pprPrecType :: TyPrec -> Type -> SDoc #

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

pprTyThingCategory :: TyThing -> SDoc #

pprShortTyThing :: TyThing -> SDoc #

pprTvBndr :: TyVarBinder -> SDoc #

pprTvBndrs :: [TyVarBinder] -> SDoc #

pprForAll :: [TyVarBinder] -> SDoc #

pprUserForAll :: [TyVarBinder] -> SDoc #

Print a user-level forall; see Note [When to print foralls]

pprSigmaType :: Type -> SDoc #

ppSuggestExplicitKinds :: SDoc #

pprTheta :: ThetaType -> SDoc #

pprThetaArrowTy :: ThetaType -> SDoc #

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

pprKind :: Kind -> SDoc #

pprParendKind :: Kind -> SDoc #

pprSourceTyCon :: TyCon -> SDoc #

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 #

Constructors

TopPrec |
FunPrec |
TyOpPrec |
TyConPrec |

Instances

Eq TyPrec # |
Instance details Defined in BasicTypes Methods (==) :: TyPrec -> TyPrec -> Bool # (/=) :: TyPrec -> TyPrec -> Bool #
Ord TyPrec # |
Instance details Defined in BasicTypes Methods compare :: TyPrec -> TyPrec -> Ordering # (<) :: TyPrec -> TyPrec -> Bool # (<=) :: TyPrec -> TyPrec -> Bool # (>) :: TyPrec -> TyPrec -> Bool # (>=) :: TyPrec -> TyPrec -> Bool # max :: TyPrec -> TyPrec -> TyPrec # min :: TyPrec -> TyPrec -> TyPrec #

maybeParen :: TyPrec -> TyPrec -> SDoc -> SDoc #

pprTyVar :: TyVar -> SDoc #

pprTyVars :: [TyVar] -> SDoc #

# Tidying type related things up for printing

tidyType :: TidyEnv -> Type -> Type #

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

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

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

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

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

tidyTyCoVarBndr :: TidyEnv -> TyCoVar -> (TidyEnv, TyCoVar) #

tidyTyCoVarBndrs :: TidyEnv -> [TyCoVar] -> (TidyEnv, [TyCoVar]) #

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.

tidyFreeTyCoVars :: TidyEnv -> [TyCoVar] -> TidyEnv #

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

tidyOpenTyCoVar :: TidyEnv -> TyCoVar -> (TidyEnv, TyCoVar) #

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

tidyOpenTyCoVars :: TidyEnv -> [TyCoVar] -> (TidyEnv, [TyCoVar]) #

tidyTyVarOcc :: TidyEnv -> TyVar -> TyVar #

tidyTopType :: Type -> Type #

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

tidyKind :: TidyEnv -> Kind -> Kind #

tidyTyVarBinder :: TidyEnv -> TyVarBndr TyVar vis -> (TidyEnv, TyVarBndr TyVar vis) #

tidyTyVarBinders :: TidyEnv -> [TyVarBndr TyVar vis] -> (TidyEnv, [TyVarBndr TyVar vis]) #