ghc-7.2.1: The GHC API

TcType

Contents

Synopsis

Documentation

type TcType = Type

type TcTyVar = TyVar

type TcKind = Kind

type TcCoVar = CoVar

data MetaDetails

Constructors

Flexi 
Indirect TcType 

data MetaInfo

Constructors

TauTv 
SigTv 
TcsTv 

mkSigmaTy :: [TyVar] -> [PredType] -> Type -> Type

tcView :: Type -> Maybe Type

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

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

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

eqType :: Type -> Type -> Bool

Type equality on source types. Does not look through newtypes or PredTypes, but it does look through type synonyms.

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

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

eqKind :: Kind -> Kind -> Bool

Tidying type related things up for printing

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

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

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

tidyTyVarBndr :: TidyEnv -> TyVar -> (TidyEnv, TyVar)

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.

tidyFreeTyVars :: TidyEnv -> TyVarSet -> TidyEnv

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

tidyOpenTyVar :: TidyEnv -> TyVar -> (TidyEnv, TyVar)

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

tidyTopType :: Type -> Type

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

type Kind = Type

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)

liftedTypeKind, argTypeKind, openTypeKind, unliftedTypeKind :: Kind

See Type for details of the distinction between these Kinds

mkArrowKind :: Kind -> Kind -> Kind

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

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

Iterated application of mkArrowKind

isUnliftedTypeKind :: Kind -> Bool

See Type for details of the distinction between these Kinds

isSubOpenTypeKind :: Kind -> Bool

True of any sub-kind of OpenTypeKind (i.e. anything except arrow)

isSubArgTypeKind :: Kind -> Bool

True of any sub-kind of ArgTypeKind

isSubKind :: Kind -> Kind -> Bool

k1 `isSubKind` k2 checks that k1 <: k2

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

Essentially splitFunTys on kinds

defaultKind :: Kind -> Kind

Used when generalising: default kind ? and ?? to *. See Type for more information on what that means

data Type

The key representation of types within the compiler

data Pred a

Constructors

ClassP Class [a]

Class predicate e.g. Eq a

IParam (IPName Name) a

Implicit parameter e.g. ?x :: Int

EqPred a a

Equality predicate e.g ty1 ~ ty2

type PredType = Pred Type

A type of the form PredTy p represents a value whose type is the Haskell predicate p, where a predicate is what occurs before the => in a Haskell type. 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

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

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

mkFunTy :: Type -> Type -> Type

Creates a function type from the given argument and result type

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

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

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

A key function: builds a TyConApp or FunTy as apppropriate 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

applyTy :: Type -> Type -> Type

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 -> [Type] -> Type

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, via dressing up polymorphic types with newtype clothing. Here's an example:

 newtype R = R (forall a. a->a)
 foo = case undefined :: R of
            R f -> f ()

mkTyConTy :: TyCon -> Type

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

mkDictTy :: Class -> [Type] -> Type

mkEqPred :: (a, a) -> Pred a

Creates a type equality predicate

data TvSubst

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 substition is only applied ONCE! This is because in general such application will not reached a fixed point.

Instances

type TvSubstEnv = TyVarEnv Type

A substitition of Types for TyVars

mkOpenTvSubst :: TvSubstEnv -> TvSubst

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

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

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

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

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

Substitute within a Type

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

Substitute within several Types

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

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

substTheta :: TvSubst -> ThetaType -> ThetaType

Substitute within a ThetaType

isUnLiftedType :: Type -> Bool

See Type for what an unlifted type is

isPrimitiveType :: Type -> Bool

Returns true of types that are opaque to Haskell. Most of these are unlifted, but now that we interact with .NET, we may have primtive (foreign-imported) types that are lifted

tyVarsOfType :: Type -> VarSet

NB: for type synonyms tyVarsOfType does not expand the synonym

pprTypeApp :: NamedThing a => a -> [Type] -> SDoc

pprPred :: (Prec -> a -> SDoc) -> Pred a -> SDoc

pprThetaArrow :: (Prec -> a -> SDoc) -> [Pred a] -> SDoc