Type

ghc-8.0.0.20160204: 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
- Type representation for the code generator
- Main type substitution data types
  - Manipulating type substitutions
  - Performing substitution on types and kinds
- Pretty-printing
- Tidying type related things up for printing

Description

Main functions for manipulating types and type-related things

Synopsis

- data TyThing
  - = AnId Id
  - | AConLike ConLike
  - | ATyCon TyCon
  - | ACoAxiom (CoAxiom Branched)
- data Type
- data VisibilityFlag
  - = Visible
  - | Specified
  - | Invisible
- 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])
- 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
- mkPiTypesPreferFunTy :: [TyVar] -> Type -> Type
- piResultTy :: Type -> Type -> Type
- piResultTys :: Type -> [Type] -> Type
- applyTys :: Type -> [KindOrType] -> Type
- applyTysD :: SDoc -> Type -> [Type] -> Type
- applyTysX :: [TyVar] -> Type -> [Type] -> Type
- dropForAlls :: Type -> Type
- mkNumLitTy :: Integer -> Type
- isNumLitTy :: Type -> Maybe Integer
- mkStrLitTy :: FastString -> Type
- isStrLitTy :: Type -> Maybe FastString
- 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
- tyConBinders :: TyCon -> [TyBinder]
- data TyCoMapper env m = TyCoMapper {
  - tcm_smart :: Bool
  - tcm_tyvar :: env -> TyVar -> m Type
  - tcm_covar :: env -> CoVar -> m Coercion
  - tcm_hole :: env -> CoercionHole -> Role -> Type -> Type -> m Coercion
  - tcm_tybinder :: env -> TyVar -> VisibilityFlag -> m (env, TyVar)
  }
- 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
  - = 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 :: VisibilityFlag -> VisibilityFlag -> Bool
- mkNamedBinder :: Var -> VisibilityFlag -> 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
- isLevityTy :: Type -> Bool
- isLevityVar :: TyVar -> Bool
- getLevity :: String -> Type -> Type
- getLevityFromKind :: String -> Type -> Type
- type Kind = Type
- typeKind :: Type -> Kind
- liftedTypeKind :: Kind
- unliftedTypeKind :: Kind
- tyCoVarsOfType :: Type -> TyCoVarSet
- tyCoVarsOfTypes :: [Type] -> TyCoVarSet
- tyCoVarsOfTypeAcc :: Type -> FV
- tyCoVarsOfTypeDSet :: Type -> DTyCoVarSet
- coVarsOfType :: Type -> CoVarSet
- coVarsOfTypes :: [Type] -> TyCoVarSet
- closeOverKinds :: TyVarSet -> TyVarSet
- splitDepVarsOfType :: Type -> Pair TyCoVarSet
- splitDepVarsOfTypes :: [Type] -> Pair TyCoVarSet
- splitVisVarsOfType :: Type -> Pair TyCoVarSet
- splitVisVarsOfTypes :: [Type] -> Pair TyCoVarSet
- expandTypeSynonyms :: Type -> Type
- typeSize :: Type -> Int
- varSetElemsWellScoped :: VarSet -> [Var]
- toposortTyVars :: [TyVar] -> [TyVar]
- tyCoVarsOfTypeWellScoped :: 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
  - = UbxTupleRep [UnaryType]
  - | UnaryRep UnaryType
- flattenRepType :: RepType -> [UnaryType]
- repType :: Type -> RepType
- tyConsOfType :: Type -> NameEnv TyCon
- typePrimRep :: UnaryType -> PrimRep
- typeRepArity :: Arity -> Type -> RepArity
- type TvSubstEnv = TyVarEnv Type
- data 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
- extendTCvInScope :: TCvSubst -> Var -> TCvSubst
- extendTCvInScopeList :: TCvSubst -> [Var] -> TCvSubst
- extendTCvInScopeSet :: TCvSubst -> VarSet -> TCvSubst
- extendTCvSubst :: TCvSubst -> Var -> Type -> TCvSubst
- extendTCvSubstList :: TCvSubst -> [Var] -> [Type] -> TCvSubst
- extendTCvSubstAndInScope :: TCvSubst -> TyCoVar -> 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 :: TCvSubst -> [Type] -> [Type]
- substTyWith :: [TyVar] -> [Type] -> Type -> Type
- substTysWith :: [TyVar] -> [Type] -> [Type] -> [Type]
- substTheta :: TCvSubst -> ThetaType -> ThetaType
- substTyAddInScope :: TCvSubst -> Type -> Type
- substTyUnchecked :: TCvSubst -> Type -> Type
- substTyVarBndr :: 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
- substTelescope :: [TyCoVar] -> [Type] -> ([Type], TCvSubst)
- 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
  - = TopPrec
  - | FunPrec
  - | TyOpPrec
  - | TyConPrec
- 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 -> TyCoVarSet -> TidyEnv
- tidyOpenTyCoVar :: TidyEnv -> TyCoVar -> (TidyEnv, TyCoVar)
- tidyOpenTyCoVars :: TidyEnv -> [TyCoVar] -> (TidyEnv, [TyCoVar])
- tidyTyVarOcc :: TidyEnv -> TyVar -> TyVar
- tidyTopType :: Type -> Type
- tidyKind :: TidyEnv -> Kind -> Kind

# Main data types representing Types

data TyThing Source

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

Eq TyThing |
Methods (==) :: TyThing -> TyThing -> Bool (/=) :: TyThing -> TyThing -> Bool
Ord TyThing |
Methods compare :: TyThing -> TyThing -> Ordering (<) :: TyThing -> TyThing -> Bool (<=) :: TyThing -> TyThing -> Bool (>) :: TyThing -> TyThing -> Bool (>=) :: TyThing -> TyThing -> Bool max :: TyThing -> TyThing -> TyThing min :: TyThing -> TyThing -> TyThing
Outputable TyThing |
Methods ppr :: TyThing -> SDoc Source pprPrec :: Rational -> TyThing -> SDoc Source
NamedThing TyThing |
Methods getOccName :: TyThing -> OccName Source getName :: TyThing -> Name Source

data Type Source

The key representation of types within the compiler

Instances

Data Type |
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 (TYPE Lifted -> TYPE Lifted) t => (forall d. Data d => c (t d)) -> Maybe (c Type) Source dataCast2 :: Typeable (TYPE Lifted -> TYPE Lifted -> TYPE Lifted) 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 |
Methods ppr :: Type -> SDoc Source pprPrec :: Rational -> Type -> SDoc Source

data VisibilityFlag Source

Is something required to appear in source Haskell (`Visible`), permitted by request (`Specified`) (visible type application), or prohibited entirely from appearing in source Haskell (`Invisible`)? Examples in Note [VisibilityFlag]

Constructors

Visible |
Specified |
Invisible |

Instances

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

type KindOrType = Type Source

type PredType = Type Source

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

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

It can be expanded into its representation, but:

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

Consider these examples:

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

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

type ThetaType = [PredType] Source

A collection of `PredType`s

data Var Source

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

Instances

Eq Var |
Methods (==) :: Var -> Var -> Bool (/=) :: Var -> Var -> Bool
Data 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 (TYPE Lifted -> TYPE Lifted) t => (forall d. Data d => c (t d)) -> Maybe (c Var) Source dataCast2 :: Typeable (TYPE Lifted -> TYPE Lifted -> TYPE Lifted) 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 |
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
Outputable Var |
Methods ppr :: Var -> SDoc Source pprPrec :: Rational -> Var -> SDoc Source
Uniquable Var |
Methods getUnique :: Var -> Unique Source
NamedThing Var |
Methods getOccName :: Var -> OccName Source getName :: Var -> Name Source
type PostRn Id ty = ty |
type PostTc Id ty = ty |

type TyVar = Var Source

isTyVar :: Var -> Bool Source

type TyCoVar = Id Source

data TyBinder Source

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]

Instances

Data TyBinder |
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 (TYPE Lifted -> TYPE Lifted) t => (forall d. Data d => c (t d)) -> Maybe (c TyBinder) Source dataCast2 :: Typeable (TYPE Lifted -> TYPE Lifted -> TYPE Lifted) 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 |
Methods ppr :: TyBinder -> SDoc Source pprPrec :: Rational -> TyBinder -> SDoc Source

## Constructing and deconstructing types

mkTyVarTy :: TyVar -> Type Source

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

getTyVar :: String -> Type -> TyVar Source

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

getTyVar_maybe :: Type -> Maybe TyVar Source

Attempts to obtain the type variable underlying a `Type`

repGetTyVar_maybe :: Type -> Maybe TyVar Source

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

getCastedTyVar_maybe :: Type -> Maybe (TyVar, Coercion) Source

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

tyVarKind :: TyVar -> Kind Source

mkAppTy :: Type -> Type -> Type Source

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

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

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

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

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

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

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

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

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

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

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

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 Source

Make an arrow type

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

Make nested arrow types

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

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

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

Attempts to extract the argument and result types from a type

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

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

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

funResultTy :: Type -> Type Source

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

funArgTy :: Type -> Type Source

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

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

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

mkTyConTy :: TyCon -> Type Source

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

tyConAppTyCon_maybe :: Type -> Maybe TyCon Source

The same as `fst . splitTyConApp`

tyConAppTyConPicky_maybe :: Type -> Maybe TyCon Source

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

tyConAppArgs_maybe :: Type -> Maybe [Type] Source

The same as `snd . splitTyConApp`

tyConAppTyCon :: Type -> TyCon Source

tyConAppArgs :: Type -> [Type] Source

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

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

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

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

tyConAppArgN :: Int -> Type -> Type Source

nextRole :: Type -> Role Source

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

splitListTyConApp_maybe :: Type -> Maybe Type Source

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

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

mkForAllTy :: TyBinder -> Type -> Type Source

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

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

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

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

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

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

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

Like mkForAllTys, but assumes all variables are dependent and visible

mkNamedForAllTy :: TyVar -> VisibilityFlag -> Type -> Type Source

Make a dependent forall.

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

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

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

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

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

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

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

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

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

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

Takes a forall type apart, or panics

splitNamedPiTys :: Type -> ([TyBinder], Type) Source

Like `splitPiTys` but split off only named binders.

mkPiType :: Var -> Type -> Type Source

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.

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

`mkPiType` for multiple type or value arguments

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

Given a list of type-level vars, makes ForAllTys, preferring anonymous binders if the variable is, in fact, not dependent. All binders are visible.

piResultTy :: Type -> Type -> Type Source

Essentially `funResultTy` on kinds handling pi-types too

piResultTys :: Type -> [Type] -> Type Source

Fold `piResultTy` over many types

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

This function is interesting because:

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

For case 2. think of:

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

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

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

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

dropForAlls :: Type -> Type Source

Drops all non-anonymous ForAllTys

mkNumLitTy :: Integer -> Type Source

isNumLitTy :: Type -> Maybe Integer Source

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

mkStrLitTy :: FastString -> Type Source

isStrLitTy :: Type -> Maybe FastString Source

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

mkCastTy :: Type -> Coercion -> Type Source

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 Source

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

userTypeError_maybe :: Type -> Maybe Type Source

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

pprUserTypeErrorTy :: Type -> SDoc Source

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

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

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

stripCoercionTy :: Type -> Coercion Source

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

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

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

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

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

filterOutInvisibleTyVars :: TyCon -> [TyVar] -> [TyVar] Source

Like `filterOutInvisibles`, but works on `TyVar`s

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

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 Source

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

tyConBinders :: TyCon -> [TyBinder] Source

data TyCoMapper env m Source

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 -> Role -> Type -> Type -> m Coercion What to do with coercion holes. See Note [Coercion holes] in TyCoRep. tcm_tybinder :: env -> TyVar -> VisibilityFlag -> m (env, TyVar) The returned env is used in the extended scope

mapType :: (Applicative m, Monad m) => TyCoMapper env m -> env -> Type -> m Type Source

mapCoercion :: (Applicative m, Monad m) => TyCoMapper env m -> env -> Coercion -> m Coercion Source

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

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

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

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

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

Where the instance tycon is :RTL, so:

    mkFamilyTyConApp :RTL Int  =  T (Maybe Int)

isDictLikeTy :: Type -> Bool Source

mkPrimEqPred :: Type -> Type -> Type Source

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

mkReprPrimEqPred :: Type -> Type -> Type Source

mkPrimEqPredRole :: Role -> Type -> Type -> PredType Source

Makes a lifted equality predicate at the given role

equalityTyCon :: Role -> TyCon Source

mkHeteroPrimEqPred :: Kind -> Kind -> Type -> Type -> Type Source

Creates a primite type equality predicate with explicit kinds

mkHeteroReprPrimEqPred :: Kind -> Kind -> Type -> Type -> Type Source

Creates a primitive representational type equality predicate with explicit kinds

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

isClassPred :: PredType -> Bool Source

isEqPred :: PredType -> Bool Source

isNomEqPred :: PredType -> Bool Source

isIPPred :: PredType -> Bool Source

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

isIPTyCon :: TyCon -> Bool Source

isIPClass :: Class -> Bool Source

isCTupleClass :: Class -> Bool Source

data PredTree Source

Constructors

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

data EqRel Source

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

Constructors

NomEq |
ReprEq |

Instances

Eq EqRel |
Methods (==) :: EqRel -> EqRel -> Bool (/=) :: EqRel -> EqRel -> Bool
Ord EqRel |
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 |
Methods ppr :: EqRel -> SDoc Source pprPrec :: Rational -> EqRel -> SDoc Source

eqRelRole :: EqRel -> Role Source

classifyPredType :: PredType -> PredTree Source

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

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

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

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

getEqPredRole :: PredType -> Role Source

predTypeEqRel :: PredType -> EqRel Source

Get the equality relation relevant for a pred type.

## Binders

sameVis :: VisibilityFlag -> VisibilityFlag -> Bool Source

Do these denote the same level of visibility? Except that `Specified` and `Invisible` are considered the same. Used for printing.

mkNamedBinder :: Var -> VisibilityFlag -> TyBinder Source

Make a named binder

mkAnonBinder :: Type -> TyBinder Source

Make an anonymous binder

isNamedBinder :: TyBinder -> Bool Source

isAnonBinder :: TyBinder -> Bool Source

isIdLikeBinder :: TyBinder -> Bool Source

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

binderVisibility :: TyBinder -> VisibilityFlag Source

binderVar_maybe :: TyBinder -> Maybe Var Source

Extract a bound variable in a binder, if any

binderVar Source

Arguments

:: String | printed if there is a panic
-> TyBinder |
-> Var |

Extract a bound variable in a binder, or panics

binderRelevantType_maybe :: TyBinder -> Maybe Type Source

Extract a relevant type, if there is one.

caseBinder Source

Arguments

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

Like `maybe`, but for binders.

partitionBinders :: [TyBinder] -> ([TyVar], [Type]) Source

Break apart a list of binders into tyvars and anonymous types.

partitionBindersIntoBinders :: [TyBinder] -> ([TyBinder], [Type]) Source

Break apart a list of binders into a list of named binders and a list of anonymous types.

binderType :: TyBinder -> Type Source

isVisibleBinder :: TyBinder -> Bool Source

Does this binder bind a visible argument?

isInvisibleBinder :: TyBinder -> Bool Source

Does this binder bind an invisible argument?

## Common type constructors

funTyCon :: TyCon Source

## Predicates on types

allDistinctTyVars :: [KindOrType] -> Bool Source

isTyVarTy :: Type -> Bool Source

isFunTy :: Type -> Bool Source

isDictTy :: Type -> Bool Source

isPredTy :: Type -> Bool Source

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

isVoidTy :: Type -> Bool Source

isCoercionTy :: Type -> Bool Source

isCoercionTy_maybe :: Type -> Maybe Coercion Source

isCoercionType :: Type -> Bool Source

Does this type classify a core Coercion?

isForAllTy :: Type -> Bool Source

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

isPiTy :: Type -> Bool Source

Is this a function or forall?

isUnLiftedType :: Type -> Bool Source

See Type for what an unlifted type is

isUnboxedTupleType :: Type -> Bool Source

isAlgType :: Type -> Bool Source

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

isClosedAlgType :: Type -> Bool Source

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

isPrimitiveType :: Type -> Bool Source

Returns true of types that are opaque to Haskell.

isStrictType :: Type -> Bool Source

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

isLevityTy :: Type -> Bool Source

Is this the type `Levity`?

isLevityVar :: TyVar -> Bool Source

Is a tyvar of type `Levity`?

getLevity Source

Arguments

:: String | Printed in case of an error
-> Type |
-> Type |

Extract the levity classifier of a type. Panics if this is not possible.

getLevityFromKind Source

Arguments

:: String | Printed in case of an error
-> Type |
-> Type |

Extract the levity classifier of a type from its kind. For example, getLevityFromKind * = Lifted; getLevityFromKind # = Unlifted. Panics if this is not possible.

# Main data types representing Kinds

type Kind = Type Source

The key type representing kinds in the compiler.

## Finding the kind of a type

typeKind :: Type -> Kind Source

## Common Kind

liftedTypeKind :: Kind Source

unliftedTypeKind :: Kind Source

# Type free variables

tyCoVarsOfType :: Type -> TyCoVarSet Source

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 Source

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

tyCoVarsOfTypeAcc :: Type -> FV Source

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 Source

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

coVarsOfTypes :: [Type] -> TyCoVarSet Source

closeOverKinds :: TyVarSet -> TyVarSet Source

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

splitDepVarsOfType :: Type -> Pair TyCoVarSet Source

Retrieve the free variables in this type, splitting them based on whether the variable was used in a dependent context. It's possible for a variable to be reported twice, if it's used both dependently and non-dependently. (This isn't the most precise analysis, because it's used in the typechecking knot. It might list some dependent variables as also non-dependent.)

splitDepVarsOfTypes :: [Type] -> Pair TyCoVarSet Source

Like `splitDepVarsOfType`, but over a list of types

splitVisVarsOfType :: Type -> Pair TyCoVarSet Source

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 Source

expandTypeSynonyms :: Type -> Type Source

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

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

typeSize :: Type -> Int Source

# Well-scoped lists of variables

varSetElemsWellScoped :: VarSet -> [Var] Source

Extract a well-scoped list of variables from a set of variables.

toposortTyVars :: [TyVar] -> [TyVar] Source

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

Get the free vars of a type in scoped order

# Type comparison

eqType :: Type -> Type -> Bool Source

Type equality on source types. Does not look through `newtypes` or `PredType`s, but it does look through type synonyms. 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 Source

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

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

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

cmpType :: Type -> Type -> Ordering Source

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

cmpTypeX :: RnEnv2 -> Type -> Type -> Ordering Source

cmpTypesX :: RnEnv2 -> [Type] -> [Type] -> Ordering Source

cmpTc :: TyCon -> TyCon -> Ordering Source

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.

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

# Forcing evaluation of types

seqType :: Type -> () Source

seqTypes :: [Type] -> () Source

# Other views onto Types

coreView :: Type -> Maybe Type Source

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 Source

Like `coreView`, but it also "expands" `Constraint` to become `TYPE Lifted`.

type UnaryType = Type Source

data RepType Source

Constructors

UbxTupleRep [UnaryType] |
UnaryRep UnaryType |

Instances

Outputable RepType |
Methods ppr :: RepType -> SDoc Source pprPrec :: Rational -> RepType -> SDoc Source

flattenRepType :: RepType -> [UnaryType] Source

repType :: Type -> RepType Source

Looks through:

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

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

tyConsOfType :: Type -> NameEnv TyCon Source

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

# Type representation for the code generator

typePrimRep :: UnaryType -> PrimRep Source

Discovers the primitive representation of a more abstract `UnaryType`

typeRepArity :: Arity -> Type -> RepArity Source

# Main type substitution data types

type TvSubstEnv = TyVarEnv Type Source

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

data TCvSubst Source

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 |
Methods ppr :: TCvSubst -> SDoc Source pprPrec :: Rational -> TCvSubst -> SDoc Source

## Manipulating type substitutions

emptyTvSubstEnv :: TvSubstEnv Source

emptyTCvSubst :: TCvSubst Source

mkEmptyTCvSubst :: InScopeSet -> TCvSubst Source

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

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

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

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

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

notElemTCvSubst :: Var -> TCvSubst -> Bool Source

getTvSubstEnv :: TCvSubst -> TvSubstEnv Source

setTvSubstEnv :: TCvSubst -> TvSubstEnv -> TCvSubst Source

zapTCvSubst :: TCvSubst -> TCvSubst Source

getTCvInScope :: TCvSubst -> InScopeSet Source

extendTCvInScope :: TCvSubst -> Var -> TCvSubst Source

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

extendTCvInScopeSet :: TCvSubst -> VarSet -> TCvSubst Source

extendTCvSubst :: TCvSubst -> Var -> Type -> TCvSubst Source

extendTCvSubstList :: TCvSubst -> [Var] -> [Type] -> TCvSubst Source

extendTCvSubstAndInScope :: TCvSubst -> TyCoVar -> Type -> TCvSubst Source

isInScope :: Var -> TCvSubst -> Bool Source

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

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

composeTCvSubst :: TCvSubst -> TCvSubst -> TCvSubst Source

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

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

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

isEmptyTCvSubst :: TCvSubst -> Bool Source

unionTCvSubst :: TCvSubst -> TCvSubst -> TCvSubst Source

## Performing substitution on types and kinds

substTy :: (?callStack :: CallStack) => TCvSubst -> Type -> Type Source

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

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

Substitute within several `Type`s

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

Type substitution, see `zipTvSubst`

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

Type substitution, see `zipTvSubst`

substTheta :: TCvSubst -> ThetaType -> ThetaType Source

Substitute within a `ThetaType`

substTyAddInScope :: TCvSubst -> Type -> Type Source

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 Source

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.

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

substTyVar :: TCvSubst -> TyVar -> Type Source

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

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

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

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

substTelescope :: [TyCoVar] -> [Type] -> ([Type], TCvSubst) Source

Create a substitution from tyvars to types, but later types may depend on earlier ones. Return the substed types and the built substitution.

# Pretty-printing

pprType :: Type -> SDoc Source

pprParendType :: Type -> SDoc Source

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

pprTyThingCategory :: TyThing -> SDoc Source

pprTyThing :: TyThing -> SDoc Source

pprTvBndr :: TyVar -> SDoc Source

pprTvBndrs :: [TyVar] -> SDoc Source

pprForAll :: [TyBinder] -> SDoc Source

Render the "forall ... ." or "forall ... ->" bit of a type. Do not pass in anonymous binders!

pprForAllImplicit :: [TyVar] -> SDoc Source

pprUserForAll :: [TyBinder] -> SDoc Source

pprSigmaType :: Type -> SDoc Source

pprTheta :: ThetaType -> SDoc Source

pprThetaArrowTy :: ThetaType -> SDoc Source

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

pprKind :: Kind -> SDoc Source

pprParendKind :: Kind -> SDoc Source

pprSourceTyCon :: TyCon -> SDoc Source

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

    data T [a] = ...

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

data TyPrec Source

Constructors

TopPrec |
FunPrec |
TyOpPrec |
TyConPrec |

Instances

Eq TyPrec |
Methods (==) :: TyPrec -> TyPrec -> Bool (/=) :: TyPrec -> TyPrec -> Bool
Ord TyPrec |
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 Source

pprTyVar :: TyVar -> SDoc Source

Print a tyvar with its kind

pprTcAppTy :: TyPrec -> (TyPrec -> Type -> SDoc) -> TyCon -> [Type] -> SDoc Source

pprPrefixApp :: TyPrec -> SDoc -> [SDoc] -> SDoc Source

pprArrowChain :: TyPrec -> [SDoc] -> SDoc Source

# Tidying type related things up for printing

tidyType :: TidyEnv -> Type -> Type Source

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

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

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

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

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

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

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

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

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

tidyFreeTyCoVars :: TidyEnv -> TyCoVarSet -> TidyEnv Source

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

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

tidyTyVarOcc :: TidyEnv -> TyVar -> TyVar Source

tidyTopType :: Type -> Type Source

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

tidyKind :: TidyEnv -> Kind -> Kind Source