ghc-7.0.3: The GHC API

Var

Contents

- The main data type and synonyms
  - Taking `Var`s apart
  - Modifying `Var`s
  - Constructing, taking apart, modifying `Id`s
  - Predicates
  - Constructing `TyVar`s
  - Taking `TyVar`s apart
  - Modifying `TyVar`s
  - Constructing `CoVar`s
  - Taking `CoVar`s apart
  - Modifying `CoVar`s

Description

GHC uses several kinds of name internally:

- `OccName.OccName`: see OccName
- `RdrName.RdrName`: see RdrName
- `Name`: see Name
- `Id.Id`: see Id
- `Var` is a synonym for the `Id.Id` type but it may additionally potentially contain type variables, which have a `Kind` rather than a `Type` and only contain some extra details during typechecking. These `Var` names may either be global or local, see Var

Global `Id`s and `Var`s are those that are imported or correspond to a data constructor, primitive operation, or record selectors. Local `Id`s and `Var`s are those bound within an expression (e.g. by a lambda) or at the top level of the module being compiled.

Synopsis

- data Var
- type TyVar = Var
- type CoVar = TyVar
- type Id = Var
- type DictId = EvId
- type DFunId = Id
- type EvVar = Var
- type EvId = Id
- type IpId = EvId
- varName :: Var -> Name
- varUnique :: Var -> Unique
- varType :: Var -> Kind
- setVarName :: Var -> Name -> Var
- setVarUnique :: Var -> Unique -> Var
- setVarType :: Id -> Type -> Id
- mkGlobalVar :: IdDetails -> Name -> Type -> IdInfo -> Id
- mkLocalVar :: IdDetails -> Name -> Type -> IdInfo -> Id
- mkExportedLocalVar :: IdDetails -> Name -> Type -> IdInfo -> Id
- idInfo :: Id -> IdInfo
- idDetails :: Id -> IdDetails
- lazySetIdInfo :: Id -> IdInfo -> Var
- setIdDetails :: Id -> IdDetails -> Id
- globaliseId :: Id -> Id
- setIdExported :: Id -> Id
- setIdNotExported :: Id -> Id
- isCoVar :: Var -> Bool
- isId :: Var -> Bool
- isTyCoVar :: Var -> Bool
- isTyVar :: Var -> Bool
- isTcTyVar :: Var -> Bool
- isLocalVar :: Var -> Bool
- isLocalId :: Var -> Bool
- isGlobalId :: Var -> Bool
- isExportedId :: Var -> Bool
- mustHaveLocalBinding :: Var -> Bool
- mkTyVar :: Name -> Kind -> TyVar
- mkTcTyVar :: Name -> Kind -> TcTyVarDetails -> TyVar
- mkWildCoVar :: Kind -> TyVar
- tyVarName :: TyVar -> Name
- tyVarKind :: TyVar -> Kind
- tcTyVarDetails :: TyVar -> TcTyVarDetails
- setTcTyVarDetails :: TyVar -> TcTyVarDetails -> TyVar
- setTyVarName :: TyVar -> Name -> TyVar
- setTyVarUnique :: TyVar -> Unique -> TyVar
- setTyVarKind :: TyVar -> Kind -> TyVar
- mkCoVar :: Name -> Kind -> CoVar
- coVarName :: CoVar -> Name
- setCoVarUnique :: CoVar -> Unique -> CoVar
- setCoVarName :: CoVar -> Name -> CoVar

# The main data type and synonyms

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 |
Data Var |
Ord Var |
Show Var |
Typeable Var |
OutputableBndr Var |
Outputable Var |
Uniquable Var |
NamedThing Var |

type TyVar = Var Source

type CoVar = TyVar Source

type Id = Var Source

type DictId = EvId Source

type DFunId = Id Source

type EvVar = Var Source

type EvId = Id Source

type IpId = EvId Source

## Taking `Var`s apart

varName :: Var -> Name Source

varUnique :: Var -> Unique Source

varType :: Var -> Kind Source

## Modifying `Var`s

setVarName :: Var -> Name -> Var Source

setVarUnique :: Var -> Unique -> Var Source

setVarType :: Id -> Type -> Id Source

## Constructing, taking apart, modifying `Id`s

mkGlobalVar :: IdDetails -> Name -> Type -> IdInfo -> Id Source

mkLocalVar :: IdDetails -> Name -> Type -> IdInfo -> Id Source

mkExportedLocalVar :: IdDetails -> Name -> Type -> IdInfo -> Id Source

Exported `Var`s will not be removed as dead code

idInfo :: Id -> IdInfo Source

idDetails :: Id -> IdDetails Source

lazySetIdInfo :: Id -> IdInfo -> Var Source

setIdDetails :: Id -> IdDetails -> Id Source

globaliseId :: Id -> Id Source

If it's a local, make it global

setIdExported :: Id -> Id Source

Exports the given local `Id`. Can also be called on global `Id`s, such as data constructors and class operations, which are born as global `Id`s and automatically exported

setIdNotExported :: Id -> Id Source

We can only do this to LocalIds

## Predicates

isCoVar :: Var -> Bool Source

isId :: Var -> Bool Source

isTyCoVar :: Var -> Bool Source

isTyVar :: Var -> Bool Source

isTcTyVar :: Var -> Bool Source

isLocalVar :: Var -> Bool Source

`isLocalVar` returns `True` for type variables as well as local `Id`s These are the variables that we need to pay attention to when finding free variables, or doing dependency analysis.

isLocalId :: Var -> Bool Source

isGlobalId :: Var -> Bool Source

isExportedId :: Var -> Bool Source

`isExportedIdVar` means "don't throw this away"

mustHaveLocalBinding :: Var -> Bool Source

`mustHaveLocalBinding` returns `True` of `Id`s and `TyVar`s that must have a binding in this module. The converse is not quite right: there are some global `Id`s that must have bindings, such as record selectors. But that doesn't matter, because it's only used for assertions

## Constructing `TyVar`s

mkTyVar :: Name -> Kind -> TyVar Source

mkTcTyVar :: Name -> Kind -> TcTyVarDetails -> TyVar Source

mkWildCoVar :: Kind -> TyVar Source

Create a type variable that is never referred to, so its unique doesn't matter

## Taking `TyVar`s apart

tyVarName :: TyVar -> Name Source

tyVarKind :: TyVar -> Kind Source

tcTyVarDetails :: TyVar -> TcTyVarDetails Source

setTcTyVarDetails :: TyVar -> TcTyVarDetails -> TyVar Source

## Modifying `TyVar`s

setTyVarName :: TyVar -> Name -> TyVar Source

setTyVarUnique :: TyVar -> Unique -> TyVar Source

setTyVarKind :: TyVar -> Kind -> TyVar Source

## Constructing `CoVar`s

mkCoVar :: Name -> Kind -> CoVar Source

## Taking `CoVar`s apart

coVarName :: CoVar -> Name Source

## Modifying `CoVar`s

setCoVarUnique :: CoVar -> Unique -> CoVar Source

setCoVarName :: CoVar -> Name -> CoVar Source