ghc-8.0.2: The GHC API

Safe Haskell None Haskell2010

TcType

Synopsis

# Documentation

type TcType = Type #

type TcTyVar = TyVar #

type TcKind = Kind #

type TcCoVar = CoVar #

type TcTyCoVar = Var #

type TcTyCon = TyCon #

data ExpType #

An expected type to check against during type-checking. See Note [ExpType] in TcMType, where you'll also find manipulators.

Constructors

 Check TcType Infer Unique TcLevel Kind (IORef (Maybe TcType))

Instances

 # Methodsppr :: ExpType -> SDoc #

Make an ExpType suitable for checking.

data SyntaxOpType #

What to expect for an argument to a rebindable-syntax operator. Quite like Type, but allows for holes to be filled in by tcSyntaxOp. The callback called from tcSyntaxOp gets a list of types; the meaning of these types is determined by a left-to-right depth-first traversal of the SyntaxOpType tree. So if you pass in

SynAny SynFun (SynList SynFun SynType Int) SynFun SynAny

you'll get three types back: one for the first SynAny, the element type of the list, and one for the last SynAny. You don't get anything for the SynType, because you've said positively that it should be an Int, and so it shall be.

This is defined here to avoid defining it in TcExpr.hs-boot.

Constructors

 SynAny Any type SynRho A rho type, deeply skolemised or instantiated as appropriate SynList A list type. You get back the element type of the list SynFun SyntaxOpType SyntaxOpType infixr 0 A function. SynType ExpType A known type.

Like SynType but accepts a regular TcType

Like mkFunTys but for SyntaxOpType

newtype TcLevel #

Constructors

 TcLevel Int

Instances

 # Methods(==) :: TcLevel -> TcLevel -> Bool #(/=) :: TcLevel -> TcLevel -> Bool # # Methods(<) :: TcLevel -> TcLevel -> Bool #(<=) :: TcLevel -> TcLevel -> Bool #(>) :: TcLevel -> TcLevel -> Bool #(>=) :: TcLevel -> TcLevel -> Bool # # Methodsppr :: TcLevel -> SDoc #

data TcTyVarDetails #

Constructors

 SkolemTv Bool FlatSkol TcType RuntimeUnk MetaTv Fields

data MetaDetails #

Constructors

 Flexi Indirect TcType

Instances

 # Methods

data MetaInfo #

Constructors

 TauTv SigTv FlatMetaTv

data TauTvFlavour #

Constructors

 VanillaTau WildcardTau A tyvar that originates from a type wildcard.

True of FlatSkol skolems only

True of both given and wanted flatten-skolems (fak and usk)

mkSpecSigmaTy :: [TyVar] -> [PredType] -> Type -> Type #

Make a sigma ty where all type variables are "specified". That is, they can be used with visible type application

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

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

Like tcSplitPiTys, but splits off only named binders, returning just the tycovars.

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

Splits a forall type into a list of TyBinders and the inner type. Always succeeds, even if it returns an empty list.

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

Like tcSplitForAllTys, but splits off only named binders.

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

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!

tcSplitSigmaTy :: Type -> ([TyVar], ThetaType, Type) #

Split a sigma type into its parts.

eqType :: Type -> Type -> Bool #

Type equality on source types. Does not look through newtypes or PredTypes, 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.

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

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

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

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

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

Like pickyEqTypeVis, but returns a Bool for convenience

Just like tcEqType, but will return True for types of different kinds as long as their non-coercion structure is identical.

Like tcEqType, but returns information about whether the difference is visible in the case of a mismatch. A return of Nothing means the types are tcEqType.

Like isRhoTy, but also says True for Infer types

Does a type represent a floating-point number?

Is a type String?

Is a type a CallStack?

Is a PredType a CallStack implicit parameter?

If so, return the name of the parameter.

Is this a ForAllTy with a named binder?

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

Does the given tyvar appear in the given type outside of any non-newtypes? Assume we're looking for a. Says "yes" for a, N a, b a, a b, b (N a). Says "no" for [a], Maybe a, T a, where N is a newtype and T is a datatype.

Does the given tyvar appear under a type generative w.r.t. representational equality? See Note [Occurs check error] in TcCanonical for the motivation for this function.

True of all Nominal equalities that are solidly insoluble This means all equalities *except* * Meta-tv non-SigTv on LHS * Meta-tv SigTv on LHS, tyvar on right

data OccCheckResult a #

Constructors

 OC_OK a OC_Forall OC_Occurs

Instances

 # Methods(>>=) :: OccCheckResult a -> (a -> OccCheckResult b) -> OccCheckResult b Source #return :: a -> OccCheckResult a Source # # Methodsfmap :: (a -> b) -> OccCheckResult a -> OccCheckResult b Source #(<\$) :: a -> OccCheckResult b -> OccCheckResult a Source # # Methodspure :: a -> OccCheckResult a Source #(<*>) :: OccCheckResult (a -> b) -> OccCheckResult a -> OccCheckResult b Source #

When inferring types, should we quantify over a given predicate? Generally true of classes; generally false of equality constraints. Equality constraints that mention quantified type variables and implicit variables complicate the story. See Notes [Inheriting implicit parameters] and [Quantifying over equality constraints]

# Finding type instances

tcTyFamInsts :: Type -> [(TyCon, [Type])] #

Finds outermost type-family applications occuring in a type, after expanding synonyms.

# Finding "exact" (non-dead) type variables

Like splitDepVarsOfType, but over a list of types

data TcDepVars #

Constructors

 DV Fieldsdv_kvs :: DTyCoVarSet dv_tvs :: DTyVarSet

Instances

 # Methods

# Extracting bound variables

Find all variables bound anywhere in a type. See also Note [Scope-check inferred kinds] in TcHsType

type Kind = Type #

The key type representing kinds in the compiler.

This version considers Constraint to be distinct from *.

Does this classify a type allowed to have values? Responds True to things like *, #, TYPE Lifted, TYPE v, Constraint.

True of any sub-kind of OpenTypeKind

data Type #

The key representation of types within the compiler

Instances

 # Methodsgfoldl :: (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 #dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c Type) Source #dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Type) Source #gmapT :: (forall b. Data b => b -> b) -> Type -> Type Source #gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Type -> r Source #gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Type -> r Source #gmapQ :: (forall d. Data d => d -> u) -> Type -> [u] Source #gmapQi :: Int -> (forall d. Data d => d -> u) -> Type -> u Source #gmapM :: Monad m => (forall d. Data d => d -> m d) -> Type -> m Type Source #gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Type -> m Type Source #gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Type -> m Type Source # # Methodsppr :: Type -> SDoc #pprPrec :: Rational -> Type -> SDoc #

type PredType = Type #

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

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

It can be expanded into its representation, but:

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

Consider these examples:

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

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

type ThetaType = [PredType] #

A collection of PredTypes

data TyBinder #

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

Instances

 # Methodsgfoldl :: (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 #dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c TyBinder) Source #dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TyBinder) Source #gmapT :: (forall b. Data b => b -> b) -> TyBinder -> TyBinder Source #gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TyBinder -> r Source #gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TyBinder -> r Source #gmapQ :: (forall d. Data d => d -> u) -> TyBinder -> [u] Source #gmapQi :: Int -> (forall d. Data d => d -> u) -> TyBinder -> u Source #gmapM :: Monad m => (forall d. Data d => d -> m d) -> TyBinder -> m TyBinder Source #gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> TyBinder -> m TyBinder Source #gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> TyBinder -> m TyBinder Source # # Methodsppr :: TyBinder -> SDoc #

data VisibilityFlag #

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

 # Methods # Methodsgfoldl :: (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 #dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c VisibilityFlag) Source #dataCast2 :: Typeable (* -> * -> *) 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 # # Methods # Methodsput_ :: BinHandle -> VisibilityFlag -> IO () #

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

Wraps foralls over the type using the provided TyVars 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

Make a dependent forall.

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

Make an arrow type

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

Make nested arrow types

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.

mkAppTy :: Type -> Type -> Type #

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

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

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

Make a named binder

Is a tyvar of type RuntimeRep?

Tests whether the given type (which should look like "TYPE ...") has any free variables

Does this binder bind a visible argument?

Does this binder bind an invisible argument?

data TCvSubst #

Type & coercion substitution

The following invariants must hold of a TCvSubst:

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

Constructors

 TCvSubst InScopeSet TvSubstEnv CvSubstEnv

Instances

 # Methodsppr :: TCvSubst -> SDoc #

A substitution of Types for TyVars and Kinds for KindVars

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!

substTyVarBndr :: (?callStack :: CallStack) => TCvSubst -> TyVar -> (TCvSubst, TyVar) #

Mkae a TCvSubst with specified tyvar subst and empty covar subst

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 Types The substitution has to satisfy the invariants described in Note [The substitution invariant].

substTyWith :: (?callStack :: CallStack) => [TyVar] -> [Type] -> Type -> Type #

Type substitution, see zipTvSubst

substTyWithCoVars :: [CoVar] -> [Coercion] -> Type -> Type #

Substitute covars within a 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].

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 Types 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.

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 Binders 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.

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.

substTheta :: (?callStack :: CallStack) => TCvSubst -> ThetaType -> ThetaType #

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

See Type for what an unlifted type is

Returns true of types that are opaque to Haskell.

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

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.

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

Gets the free vars of a telescope, scoped over a given free var set.

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)

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.

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

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

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

tyCoVarsOfTypesList :: [Type] -> [TyCoVar] #

Returns free variables of types, including kind variables as a deterministically ordered list. For type synonyms it does not expand the synonym.

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