ghc-7.10.3: The GHC API

Safe HaskellNone




GHC uses several kinds of name internally:

Names are one of:

  • External, if they name things declared in other modules. Some external Names are wired in, i.e. they name primitives defined in the compiler itself
  • Internal, if they name things in the module being compiled. Some internal Names are system names, if they are names manufactured by the compiler


The main types

data Name Source

A unique, unambigious name for something, containing information about where that thing originated.

data BuiltInSyntax Source

BuiltInSyntax is for things like (:), [] and tuples, which have special syntactic forms. They aren't in scope as such.



Creating Names

mkSystemName :: Unique -> OccName -> Name Source

Create a name brought into being by the compiler

mkInternalName :: Unique -> OccName -> SrcSpan -> Name Source

Create a name which is (for now at least) local to the current module and hence does not need a Module to disambiguate it from other Names

mkFCallName :: Unique -> String -> Name Source

Make a name for a foreign call

mkExternalName :: Unique -> Module -> OccName -> SrcSpan -> Name Source

Create a name which definitely originates in the given module

mkWiredInName :: Module -> OccName -> Unique -> TyThing -> BuiltInSyntax -> Name Source

Create a name which is actually defined by the compiler itself

Manipulating and deconstructing Names

localiseName :: Name -> Name Source

Make the Name into an internal name, regardless of what it was to begin with

mkLocalisedOccName :: Module -> (Maybe String -> OccName -> OccName) -> Name -> OccName Source

Create a localised variant of a name.

If the name is external, encode the original's module name to disambiguate. SPJ says: this looks like a rather odd-looking function; but it seems to be used only during vectorisation, so I'm not going to worry

Predicates on Names

nameIsLocalOrFrom :: Module -> Name -> Bool Source

Returns True if the name is (a) Internal (b) External but from the specified module (c) External but from the interactive package

The key idea is that False means: the entity is defined in some other module you can find the details (type, fixity, instances) in some interface file those details will be stored in the EPT or HPT

True means: the entity is defined in this module or earlier in the GHCi session you can find details (type, fixity, instances) in the TcGblEnv or TcLclEnv

The isInteractiveModule part is because successive interactions of a GCHi session each give rise to a fresh module (Ghci1, Ghci2, etc), but they all come from the magic interactive package; and all the details are kept in the TcLclEnv, TcGblEnv, NOT in the HPT or EPT. See Note [The interactive package] in HscTypes

Class NamedThing and overloaded friends

class NamedThing a where Source

A class allowing convenient access to the Name of various datatypes

Minimal complete definition



getOccName :: a -> OccName Source

getName :: a -> Name Source

module OccName