ghc-7.10.0.20150316: The GHC API

Safe HaskellNone
LanguageHaskell2010

TcType

Contents

Synopsis

Documentation

newtype TcLevel Source

Constructors

TcLevel Int 

isFskTyVar :: TcTyVar -> Bool Source

True of FlatSkol skolems only

isFlattenTyVar :: TcTyVar -> Bool Source

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

mkTcReprEqPred :: TcType -> TcType -> Type Source

Make a representational equality predicate

mkTcEqPredRole :: Role -> TcType -> TcType -> Type Source

Make an equality predicate at a given role. The role must not be Phantom.

tcView :: Type -> Maybe Type Source

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

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

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!

eqType :: Type -> Type -> Bool Source

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

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

isTyVarExposed :: TcTyVar -> TcType -> Bool Source

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.

Finding type instances

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

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

Finding "exact" (non-dead) type variables

type Kind = Type Source

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

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

unliftedTypeKind :: Kind Source

See Type for details of the distinction between these Kinds

liftedTypeKind :: Kind Source

See Type for details of the distinction between these Kinds

openTypeKind :: Kind Source

See Type for details of the distinction between these Kinds

constraintKind :: Kind Source

See Type for details of the distinction between these Kinds

mkArrowKind :: Kind -> Kind -> Kind Source

Given two kinds k1 and k2, creates the Kind k1 -> k2

mkArrowKinds :: [Kind] -> Kind -> Kind Source

Iterated application of mkArrowKind

isUnliftedTypeKind :: Kind -> Bool Source

See Type for details of the distinction between these Kinds

isSubOpenTypeKind :: Kind -> Bool Source

True of any sub-kind of OpenTypeKind

splitKindFunTys :: Kind -> ([Kind], Kind) Source

Essentially splitFunTys on kinds

data Type Source

The key representation of types within the compiler

Instances

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 PredTypes

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

Wraps foralls over the type using the provided TyVars from left to right

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

Creates a function type from the given argument and result type

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

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

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

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

mkAppTy :: Type -> Type -> Type Source

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

applyTy :: Type -> KindOrType -> Type Source

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

f t1 t2

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

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

This function is interesting because:

  1. The function may have more for-alls than there are args

    1. 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 undefineds type.

mkTyConTy :: TyCon -> Type Source

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

mkEqPred :: Type -> Type -> PredType Source

Creates a type equality predicate

data TvSubst Source

Type substitution

The following invariants must hold of a TvSubst:

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

type TvSubstEnv = TyVarEnv Type Source

A substitution of Types for TyVars and Kinds for KindVars

mkOpenTvSubst :: TvSubstEnv -> TvSubst Source

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

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

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

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

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

substTy :: TvSubst -> Type -> Type Source

Substitute within a Type

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

Substitute within several Types

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

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

isUnLiftedType :: Type -> Bool Source

See Type for what an unlifted type is

isPrimitiveType :: Type -> Bool Source

Returns true of types that are opaque to Haskell.

tyVarsOfType :: Type -> VarSet Source

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