Safe Haskell | None |
---|---|
Language | Haskell2010 |
- Main data types representing Types
- Main data types representing Kinds
- Type free variables
- Well-scoped lists of variables
- Type comparison
- Forcing evaluation of types
- Other views onto Types
- Type representation for the code generator
- Main type substitution data types
- Pretty-printing
- Tidying type related things up for printing
Main functions for manipulating types and type-related things
- data TyThing
- data Type
- data VisibilityFlag
- type KindOrType = Type
- type PredType = Type
- type ThetaType = [PredType]
- data Var
- type TyVar = Var
- isTyVar :: Var -> Bool
- type TyCoVar = Id
- data TyBinder
- 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, Coercion)
- tyVarKind :: TyVar -> Kind
- mkAppTy :: Type -> Type -> Type
- mkAppTys :: Type -> [Type] -> Type
- splitAppTy :: Type -> (Type, Type)
- splitAppTys :: Type -> (Type, [Type])
- repSplitAppTys :: Type -> (Type, [Type])
- splitAppTy_maybe :: Type -> Maybe (Type, Type)
- repSplitAppTy_maybe :: 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)
- splitFunTysN :: Int -> 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 :: Type -> Maybe (TyCon, [Type])
- splitTyConApp :: Type -> (TyCon, [Type])
- tyConAppArgN :: Int -> Type -> Type
- nextRole :: Type -> Role
- splitListTyConApp_maybe :: Type -> Maybe Type
- repSplitTyConApp_maybe :: Type -> Maybe (TyCon, [Type])
- mkForAllTy :: TyBinder -> Type -> Type
- mkForAllTys :: [TyBinder] -> Type -> Type
- mkInvForAllTys :: [TyVar] -> Type -> Type
- mkSpecForAllTys :: [TyVar] -> Type -> Type
- mkVisForAllTys :: [TyVar] -> Type -> Type
- mkNamedForAllTy :: TyVar -> VisibilityFlag -> Type -> Type
- splitForAllTy_maybe :: Type -> Maybe (TyVar, Type)
- splitForAllTys :: Type -> ([TyVar], Type)
- splitForAllTy :: Type -> (TyVar, Type)
- splitPiTy_maybe :: Type -> Maybe (TyBinder, Type)
- splitPiTys :: Type -> ([TyBinder], Type)
- splitPiTy :: Type -> (TyBinder, Type)
- splitNamedPiTys :: Type -> ([TyBinder], Type)
- mkPiType :: Var -> Type -> Type
- mkPiTypes :: [Var] -> Type -> Type
- mkTyBindersPreferAnon :: [TyVar] -> Type -> [TyBinder]
- piResultTy :: Type -> Type -> Type
- piResultTys :: 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
- 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]
- filterOutInvisibleTyVars :: TyCon -> [TyVar] -> [TyVar]
- partitionInvisibles :: TyCon -> (a -> Type) -> [a] -> ([a], [a])
- synTyConResKind :: TyCon -> Kind
- data TyCoMapper env m = TyCoMapper {}
- mapType :: (Applicative m, Monad m) => TyCoMapper env m -> env -> Type -> m Type
- mapCoercion :: (Applicative m, 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
- data EqRel
- 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 :: VisibilityFlag -> VisibilityFlag -> Bool
- mkNamedBinder :: VisibilityFlag -> Var -> TyBinder
- mkNamedBinders :: VisibilityFlag -> [TyVar] -> [TyBinder]
- mkAnonBinder :: Type -> TyBinder
- isNamedBinder :: TyBinder -> Bool
- isAnonBinder :: TyBinder -> Bool
- isIdLikeBinder :: TyBinder -> Bool
- binderVisibility :: TyBinder -> VisibilityFlag
- binderVar_maybe :: TyBinder -> Maybe Var
- binderVar :: String -> TyBinder -> Var
- binderRelevantType_maybe :: TyBinder -> Maybe Type
- caseBinder :: TyBinder -> (TyVar -> a) -> (Type -> a) -> a
- partitionBinders :: [TyBinder] -> ([TyVar], [Type])
- partitionBindersIntoBinders :: [TyBinder] -> ([TyBinder], [Type])
- binderType :: TyBinder -> Type
- isVisibleBinder :: TyBinder -> Bool
- isInvisibleBinder :: TyBinder -> Bool
- funTyCon :: TyCon
- allDistinctTyVars :: [KindOrType] -> Bool
- isTyVarTy :: Type -> Bool
- isFunTy :: Type -> Bool
- isDictTy :: Type -> Bool
- isPredTy :: Type -> Bool
- isVoidTy :: Type -> Bool
- isCoercionTy :: Type -> Bool
- isCoercionTy_maybe :: Type -> Maybe Coercion
- isCoercionType :: Type -> Bool
- isForAllTy :: Type -> Bool
- isPiTy :: Type -> Bool
- isUnliftedType :: Type -> Bool
- isUnboxedTupleType :: Type -> Bool
- isAlgType :: Type -> Bool
- isClosedAlgType :: Type -> Bool
- isPrimitiveType :: Type -> Bool
- isStrictType :: Type -> Bool
- isRuntimeRepTy :: Type -> Bool
- isRuntimeRepVar :: TyVar -> Bool
- isRuntimeRepKindedTy :: Type -> Bool
- dropRuntimeRepArgs :: [Type] -> [Type]
- getRuntimeRep :: String -> Type -> Type
- getRuntimeRepFromKind :: String -> Type -> Type
- type Kind = Type
- typeKind :: Type -> Kind
- liftedTypeKind :: Kind
- tyCoVarsOfType :: Type -> TyCoVarSet
- tyCoVarsOfTypes :: [Type] -> TyCoVarSet
- tyCoFVsOfType :: Type -> FV
- tyCoVarsOfTypeDSet :: Type -> DTyCoVarSet
- coVarsOfType :: Type -> CoVarSet
- coVarsOfTypes :: [Type] -> TyCoVarSet
- closeOverKinds :: TyVarSet -> TyVarSet
- closeOverKindsList :: [TyVar] -> [TyVar]
- splitVisVarsOfType :: Type -> Pair TyCoVarSet
- splitVisVarsOfTypes :: [Type] -> Pair TyCoVarSet
- expandTypeSynonyms :: Type -> Type
- typeSize :: Type -> Int
- dVarSetElemsWellScoped :: DVarSet -> [Var]
- toposortTyVars :: [TyVar] -> [TyVar]
- tyCoVarsOfTypeWellScoped :: Type -> [TyVar]
- tyCoVarsOfTypesWellScoped :: [Type] -> [TyVar]
- eqType :: Type -> Type -> Bool
- eqTypeX :: RnEnv2 -> Type -> Type -> Bool
- eqTypes :: [Type] -> [Type] -> Bool
- cmpType :: Type -> Type -> Ordering
- cmpTypes :: [Type] -> [Type] -> Ordering
- cmpTypeX :: RnEnv2 -> Type -> Type -> Ordering
- cmpTypesX :: RnEnv2 -> [Type] -> [Type] -> Ordering
- cmpTc :: TyCon -> TyCon -> Ordering
- eqVarBndrs :: RnEnv2 -> [Var] -> [Var] -> Maybe RnEnv2
- seqType :: Type -> ()
- seqTypes :: [Type] -> ()
- coreView :: Type -> Maybe Type
- coreViewOneStarKind :: Type -> Maybe Type
- type UnaryType = Type
- data RepType
- flattenRepType :: RepType -> [UnaryType]
- repType :: Type -> RepType
- tyConsOfType :: Type -> NameEnv TyCon
- typePrimRep :: UnaryType -> PrimRep
- typeRepArity :: Arity -> Type -> RepArity
- tyConPrimRep :: TyCon -> PrimRep
- 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
- extendTvSubstList :: TCvSubst -> [Var] -> [Type] -> TCvSubst
- extendTvSubstAndInScope :: TCvSubst -> TyVar -> Type -> 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 :: (?callStack :: CallStack) => TCvSubst -> Type -> Type
- substTys :: (?callStack :: CallStack) => TCvSubst -> [Type] -> [Type]
- substTyWith :: (?callStack :: CallStack) => [TyVar] -> [Type] -> Type -> Type
- substTysWith :: [TyVar] -> [Type] -> [Type] -> [Type]
- substTheta :: (?callStack :: CallStack) => TCvSubst -> ThetaType -> ThetaType
- substTyAddInScope :: TCvSubst -> Type -> Type
- substTyUnchecked :: TCvSubst -> Type -> Type
- substTysUnchecked :: TCvSubst -> [Type] -> [Type]
- substThetaUnchecked :: TCvSubst -> ThetaType -> ThetaType
- substTyWithBindersUnchecked :: [TyBinder] -> [Type] -> Type -> Type
- substTyWithUnchecked :: [TyVar] -> [Type] -> Type -> Type
- substCoUnchecked :: TCvSubst -> Coercion -> Coercion
- substCoWithUnchecked :: [TyVar] -> [Type] -> Coercion -> Coercion
- substTyVarBndr :: (?callStack :: CallStack) => 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
- pprTypeApp :: TyCon -> [Type] -> SDoc
- pprTyThingCategory :: TyThing -> SDoc
- pprTyThing :: TyThing -> SDoc
- pprTvBndr :: TyVar -> SDoc
- pprTvBndrs :: [TyVar] -> SDoc
- pprForAll :: [TyBinder] -> SDoc
- pprForAllImplicit :: [TyVar] -> SDoc
- pprUserForAll :: [TyBinder] -> 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
- maybeParen :: TyPrec -> TyPrec -> SDoc -> SDoc
- pprTyVar :: TyVar -> SDoc
- pprTcAppTy :: TyPrec -> (TyPrec -> Type -> SDoc) -> TyCon -> [Type] -> SDoc
- pprPrefixApp :: TyPrec -> SDoc -> [SDoc] -> SDoc
- pprArrowChain :: TyPrec -> [SDoc] -> 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
- tidyTyBinder :: TidyEnv -> TyBinder -> (TidyEnv, TyBinder)
- tidyTyBinders :: TidyEnv -> [TyBinder] -> (TidyEnv, [TyBinder])
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
ornewtype
. 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 VisibilityFlag #
type KindOrType = 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"
A TyBinder
represents an argument to a function. TyBinders can be dependent
(Named
) or nondependent (Anon
). They may also be visible or not.
See also Note [TyBinder]
Constructing and deconstructing types
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
repGetTyVar_maybe :: Type -> Maybe TyVar #
Attempts to obtain the type variable underlying a Type
, without
any expansion
getCastedTyVar_maybe :: Type -> Maybe (TyVar, Coercion) #
If the type is a tyvar, possibly under a cast, returns it, along with the coercion. Thus, the co is :: kind tv ~R kind 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 :: 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 :: 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)
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) #
splitFunTysN :: Int -> Type -> ([Type], Type) #
Split off exactly the given number argument types, and panics if that is not possible
funResultTy :: Type -> Type #
Extract the function result 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.
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 :: 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 #
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!
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 :: Type -> Maybe (TyCon, [Type]) #
Like splitTyConApp_maybe
, but doesn't look through synonyms. This
assumes the synonyms have already been dealt with.
mkForAllTy :: TyBinder -> Type -> Type #
mkForAllTys :: [TyBinder] -> 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 invisible, 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
mkNamedForAllTy :: TyVar -> VisibilityFlag -> Type -> Type #
Make a dependent forall.
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
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.
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
splitPiTys :: Type -> ([TyBinder], Type) #
Split off all TyBinders to a type, splitting both proper foralls and functions
splitNamedPiTys :: Type -> ([TyBinder], Type) #
Like splitPiTys
but split off only named binders.
mkPiType :: 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 Invisible binders.
mkTyBindersPreferAnon :: [TyVar] -> Type -> [TyBinder] #
Given a list of type-level vars and a result type, makes TyBinders, preferring anonymous binders if the variable is, in fact, not dependent. All binders are visible.
piResultTy :: Type -> Type -> Type #
Just like piResultTys
but for a single argument
Try not to iterate piResultTy
, because it's inefficient to substitute
one variable at a time; instead use 'piResultTys"
piResultTys :: 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.
dropForAlls :: Type -> Type #
Drops all non-anonymous 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.
mkCastTy :: Type -> Coercion -> Type #
Make a CastTy
. The Coercion must be nominal. This function looks
at the entire structure of the type and coercion in an attempt to
maintain representation invariance (that is, any two types that are eqType
look the same). Be very wary of calling this in a loop.
mkCoercionTy :: Coercion -> Type #
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
filterOutInvisibleTyVars :: TyCon -> [TyVar] -> [TyVar] #
Like filterOutInvisibles
, but works on TyVar
s
partitionInvisibles :: TyCon -> (a -> Type) -> [a] -> ([a], [a]) #
Given a tycon and a list of things (which correspond to arguments), partitions the things into the invisible ones and the visible 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 #
data TyCoMapper env m #
This describes how a "map" operation over a type/coercion should behave
TyCoMapper | |
|
mapType :: (Applicative m, Monad m) => TyCoMapper env m -> env -> Type -> m Type #
mapCoercion :: (Applicative m, 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 #
isNomEqPred :: PredType -> Bool #
isIPPred_maybe :: Type -> Maybe (FastString, Type) #
isCTupleClass :: Class -> Bool #
classifyPredType :: PredType -> PredTree #
getClassPredTys :: PredType -> (Class, [Type]) #
getEqPredTys :: PredType -> (Type, Type) #
getEqPredRole :: PredType -> Role #
predTypeEqRel :: PredType -> EqRel #
Get the equality relation relevant for a pred type.
Binders
sameVis :: VisibilityFlag -> VisibilityFlag -> Bool #
mkNamedBinder :: VisibilityFlag -> Var -> TyBinder #
Make a named binder
mkNamedBinders :: VisibilityFlag -> [TyVar] -> [TyBinder] #
Make many named binders
mkAnonBinder :: Type -> TyBinder #
Make an anonymous binder
isNamedBinder :: TyBinder -> Bool #
isAnonBinder :: TyBinder -> Bool #
isIdLikeBinder :: TyBinder -> Bool #
Does this binder bind a variable that is not erased? Returns
True
for anonymous binders.
binderVar_maybe :: TyBinder -> Maybe Var #
Extract a bound variable in a binder, if any
Extract a bound variable in a binder, or panics
binderRelevantType_maybe :: TyBinder -> Maybe Type #
Extract a relevant type, if there is one.
Like maybe
, but for binders.
partitionBinders :: [TyBinder] -> ([TyVar], [Type]) #
Break apart a list of binders into tyvars and anonymous types.
partitionBindersIntoBinders :: [TyBinder] -> ([TyBinder], [Type]) #
Break apart a list of binders into a list of named binders and a list of anonymous types.
binderType :: TyBinder -> Type #
isVisibleBinder :: TyBinder -> Bool #
Does this binder bind a visible argument?
isInvisibleBinder :: TyBinder -> Bool #
Does this binder bind an invisible argument?
Common type constructors
Predicates on types
allDistinctTyVars :: [KindOrType] -> Bool #
isCoercionTy :: Type -> Bool #
isCoercionTy_maybe :: Type -> Maybe Coercion #
isCoercionType :: Type -> Bool #
isForAllTy :: Type -> Bool #
Checks whether this is a proper forall (with a named binder)
isUnliftedType :: Type -> Bool #
See Type for what an unlifted type is
isUnboxedTupleType :: 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
isClosedAlgType :: 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. Closed type constructors are those with a fixed right hand side, as opposed to e.g. associated types
isPrimitiveType :: Type -> Bool #
Returns true of types that are opaque to Haskell.
isStrictType :: 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
.
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. PtrRep)
dropRuntimeRepArgs :: [Type] -> [Type] #
Extract the RuntimeRep classifier of a type. Panics if this is not possible.
Extract the RuntimeRep classifier of a type from its kind. For example, getRuntimeRepFromKind * = PtrRepLifted; getRuntimeRepFromKind # = PtrRepUnlifted. Panics if this is not possible.
Main data types representing Kinds
Finding the kind of a type
Common Kind
liftedTypeKind :: Kind #
Type free variables
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.
tyCoFVsOfType :: Type -> FV #
The worker for tyVarsOfType
and tyVarsOfTypeList
.
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)
tyCoVarsOfTypeDSet :: Type -> DTyCoVarSet #
tyVarsOfType
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.
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.
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 :: [TyVar] -> [TyVar] #
Do a topological sort on a list of tyvars. 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.
cmpTc :: 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 [cmpType nondeterminism]
Forcing evaluation of types
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.
By being non-recursive and inlined, this case analysis gets efficiently joined onto the case analysis that the caller is already doing
coreViewOneStarKind :: Type -> Maybe Type #
Like coreView
, but it also "expands" Constraint
to become
TYPE PtrRepLifted
.
flattenRepType :: RepType -> [UnaryType] #
repType
figure out how a type will be represented
at runtime. It looks through
- For-alls
- Synonyms
- Predicates
- All newtypes, including recursive ones, but not newtype families
- Casts
tyConsOfType :: Type -> NameEnv 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.
Type representation for the code generator
typePrimRep :: UnaryType -> PrimRep #
Discovers the primitive representation of a more abstract UnaryType
typeRepArity :: Arity -> Type -> RepArity #
tyConPrimRep :: TyCon -> PrimRep #
Find the primitive representation of a TyCon
. Defined here to
avoid module loops. Call this only on unlifted tycons.
Main type substitution data types
Type & coercion substitution
The following invariants must hold of a TCvSubst
:
- The in-scope set is needed only to guide the generation of fresh uniques
- In particular, the kind of the type variables in the in-scope set is not relevant
- The substitution is only applied ONCE! This is because in general such application will not reach a fixed point.
Manipulating type substitutions
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 #
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 :: (?callStack :: CallStack) => TCvSubst -> Type -> Type #
Substitute within a Type
The substitution has to satisfy the invariants described in
Note [The substitution invariant].
substTys :: (?callStack :: CallStack) => TCvSubst -> [Type] -> [Type] #
Substitute within several Type
s
The substitution has to satisfy the invariants described in
Note [The substitution invariant].
substTyWith :: (?callStack :: CallStack) => [TyVar] -> [Type] -> Type -> Type #
Type substitution, see zipTvSubst
substTysWith :: [TyVar] -> [Type] -> [Type] -> [Type] #
Type substitution, see zipTvSubst
substTheta :: (?callStack :: CallStack) => 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.
substTyWithBindersUnchecked :: [TyBinder] -> [Type] -> Type -> Type #
Type substitution using Binder
s disabling the sanity checks.
Anonymous binders simply ignore their matching type.
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.
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.
substTyVar :: TCvSubst -> TyVar -> Type #
substTyVars :: TCvSubst -> [TyVar] -> [Type] #
cloneTyVarBndrs :: TCvSubst -> [TyVar] -> UniqSupply -> (TCvSubst, [TyVar]) #
Pretty-printing
pprParendType :: Type -> SDoc #
pprTypeApp :: TyCon -> [Type] -> SDoc #
pprTyThingCategory :: TyThing -> SDoc #
pprTyThing :: TyThing -> SDoc #
pprTvBndrs :: [TyVar] -> SDoc #
pprForAll :: [TyBinder] -> SDoc #
Render the "forall ... ." or "forall ... ->" bit of a type. Do not pass in anonymous binders!
pprForAllImplicit :: [TyVar] -> SDoc #
pprUserForAll :: [TyBinder] -> SDoc #
pprSigmaType :: Type -> SDoc #
pprThetaArrowTy :: ThetaType -> SDoc #
pprClassPred :: Class -> [Type] -> SDoc #
pprParendKind :: Kind -> SDoc #
pprSourceTyCon :: TyCon -> SDoc #
pprArrowChain :: TyPrec -> [SDoc] -> SDoc #
Tidying type related things up for printing
tidyOpenTypes :: TidyEnv -> [Type] -> (TidyEnv, [Type]) #
Grabs the free type variables, tidies them
and then uses tidyType
to work over the type itself
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
tidyTyVarOcc :: TidyEnv -> TyVar -> TyVar #
tidyTopType :: Type -> Type #
Calls tidyType
on a top-level type (i.e. with an empty tidying environment)