ghc-7.0.3: The GHC API

OccName

Contents

- The `NameSpace` type
  - Construction
  - Pretty Printing
- The `OccName` type
  - Construction
  - Derived `OccName`s
  - Deconstruction
- The `OccEnv` type
- The `OccSet` type
- Tidying up
- Lexical characteristics of Haskell names

Description

GHC uses several kinds of name internally:

- `OccName` represents names as strings with just a little more information: the "namespace" that the name came from, e.g. the namespace of value, type constructors or data constructors
- `RdrName.RdrName`: see RdrName
- `Name.Name`: see Name
- `Id.Id`: see Id
- `Var.Var`: see Var

Synopsis

- data NameSpace
- tcName :: NameSpace
- clsName :: NameSpace
- tcClsName :: NameSpace
- dataName :: NameSpace
- varName :: NameSpace
- tvName :: NameSpace
- srcDataName :: NameSpace
- pprNameSpace :: NameSpace -> SDoc
- pprNonVarNameSpace :: NameSpace -> SDoc
- pprNameSpaceBrief :: NameSpace -> SDoc
- data OccName
- pprOccName :: OccName -> SDoc
- mkOccName :: NameSpace -> String -> OccName
- mkOccNameFS :: NameSpace -> FastString -> OccName
- mkVarOcc :: String -> OccName
- mkVarOccFS :: FastString -> OccName
- mkDataOcc :: String -> OccName
- mkDataOccFS :: FastString -> OccName
- mkTyVarOcc :: String -> OccName
- mkTyVarOccFS :: FastString -> OccName
- mkTcOcc :: String -> OccName
- mkTcOccFS :: FastString -> OccName
- mkClsOcc :: String -> OccName
- mkClsOccFS :: FastString -> OccName
- mkDFunOcc :: String -> Bool -> OccSet -> OccName
- mkTupleOcc :: NameSpace -> Boxity -> Arity -> OccName
- setOccNameSpace :: NameSpace -> OccName -> OccName
- isDerivedOccName :: OccName -> Bool
- mkDataConWrapperOcc :: OccName -> OccName
- mkWorkerOcc :: OccName -> OccName
- mkDefaultMethodOcc :: OccName -> OccName
- mkDerivedTyConOcc :: OccName -> OccName
- mkNewTyCoOcc :: OccName -> OccName
- mkClassOpAuxOcc :: OccName -> OccName
- mkCon2TagOcc :: OccName -> OccName
- mkTag2ConOcc :: OccName -> OccName
- mkMaxTagOcc :: OccName -> OccName
- mkClassTyConOcc :: OccName -> OccName
- mkClassDataConOcc :: OccName -> OccName
- mkDictOcc :: OccName -> OccName
- mkIPOcc :: OccName -> OccName
- mkSpecOcc :: OccName -> OccName
- mkForeignExportOcc :: OccName -> OccName
- mkGenOcc1 :: OccName -> OccName
- mkGenOcc2 :: OccName -> OccName
- mkDataTOcc :: OccName -> OccName
- mkDataCOcc :: OccName -> OccName
- mkDataConWorkerOcc :: OccName -> OccName
- mkSuperDictSelOcc :: Int -> OccName -> OccName
- mkLocalOcc :: Unique -> OccName -> OccName
- mkMethodOcc :: OccName -> OccName
- mkInstTyTcOcc :: String -> OccSet -> OccName
- mkInstTyCoOcc :: OccName -> OccName
- mkEqPredCoOcc :: OccName -> OccName
- mkVectOcc :: OccName -> OccName
- mkVectTyConOcc :: OccName -> OccName
- mkVectDataConOcc :: OccName -> OccName
- mkVectIsoOcc :: OccName -> OccName
- mkPDataTyConOcc :: OccName -> OccName
- mkPDataDataConOcc :: OccName -> OccName
- mkPReprTyConOcc :: OccName -> OccName
- mkPADFunOcc :: OccName -> OccName
- occNameFS :: OccName -> FastString
- occNameString :: OccName -> String
- occNameSpace :: OccName -> NameSpace
- isVarOcc :: OccName -> Bool
- isTvOcc :: OccName -> Bool
- isTcOcc :: OccName -> Bool
- isDataOcc :: OccName -> Bool
- isDataSymOcc :: OccName -> Bool
- isSymOcc :: OccName -> Bool
- isValOcc :: OccName -> Bool
- parenSymOcc :: OccName -> SDoc -> SDoc
- startsWithUnderscore :: OccName -> Bool
- isTcClsNameSpace :: NameSpace -> Bool
- isTvNameSpace :: NameSpace -> Bool
- isDataConNameSpace :: NameSpace -> Bool
- isVarNameSpace :: NameSpace -> Bool
- isValNameSpace :: NameSpace -> Bool
- isTupleOcc_maybe :: OccName -> Maybe (NameSpace, Boxity, Arity)
- data OccEnv a
- emptyOccEnv :: OccEnv a
- unitOccEnv :: OccName -> a -> OccEnv a
- extendOccEnv :: OccEnv a -> OccName -> a -> OccEnv a
- mapOccEnv :: (a -> b) -> OccEnv a -> OccEnv b
- lookupOccEnv :: OccEnv a -> OccName -> Maybe a
- mkOccEnv :: [(OccName, a)] -> OccEnv a
- mkOccEnv_C :: (a -> a -> a) -> [(OccName, a)] -> OccEnv a
- extendOccEnvList :: OccEnv a -> [(OccName, a)] -> OccEnv a
- elemOccEnv :: OccName -> OccEnv a -> Bool
- occEnvElts :: OccEnv a -> [a]
- foldOccEnv :: (a -> b -> b) -> b -> OccEnv a -> b
- plusOccEnv :: OccEnv a -> OccEnv a -> OccEnv a
- plusOccEnv_C :: (a -> a -> a) -> OccEnv a -> OccEnv a -> OccEnv a
- extendOccEnv_C :: (a -> a -> a) -> OccEnv a -> OccName -> a -> OccEnv a
- extendOccEnv_Acc :: (a -> b -> b) -> (a -> b) -> OccEnv b -> OccName -> a -> OccEnv b
- filterOccEnv :: (elt -> Bool) -> OccEnv elt -> OccEnv elt
- delListFromOccEnv :: OccEnv a -> [OccName] -> OccEnv a
- delFromOccEnv :: OccEnv a -> OccName -> OccEnv a
- type OccSet = UniqSet OccName
- emptyOccSet :: OccSet
- unitOccSet :: OccName -> OccSet
- mkOccSet :: [OccName] -> OccSet
- extendOccSet :: OccSet -> OccName -> OccSet
- extendOccSetList :: OccSet -> [OccName] -> OccSet
- unionOccSets :: OccSet -> OccSet -> OccSet
- unionManyOccSets :: [OccSet] -> OccSet
- minusOccSet :: OccSet -> OccSet -> OccSet
- elemOccSet :: OccName -> OccSet -> Bool
- occSetElts :: OccSet -> [OccName]
- foldOccSet :: (OccName -> b -> b) -> b -> OccSet -> b
- isEmptyOccSet :: OccSet -> Bool
- intersectOccSet :: OccSet -> OccSet -> OccSet
- intersectsOccSet :: OccSet -> OccSet -> Bool
- type TidyOccEnv = OccEnv Int
- emptyTidyOccEnv :: TidyOccEnv
- tidyOccName :: TidyOccEnv -> OccName -> (TidyOccEnv, OccName)
- initTidyOccEnv :: [OccName] -> TidyOccEnv
- isLexCon :: FastString -> Bool
- isLexVar :: FastString -> Bool
- isLexId :: FastString -> Bool
- isLexSym :: FastString -> Bool
- isLexConId :: FastString -> Bool
- isLexConSym :: FastString -> Bool
- isLexVarId :: FastString -> Bool
- isLexVarSym :: FastString -> Bool
- startsVarSym :: Char -> Bool
- startsVarId :: Char -> Bool
- startsConSym :: Char -> Bool
- startsConId :: Char -> Bool

# The `NameSpace` type

data NameSpace Source

Instances

Eq NameSpace |
Ord NameSpace |
Binary NameSpace |

## Construction

There are two forms of data constructor:

Source data constructors
  The data constructors mentioned in Haskell source code
Real data constructors
  The data constructors of the representation type, which may not be the same as the source type

For example:

     data T = T !(Int, Int)

The source datacon has type `(Int, Int) -> T` The real datacon has type `Int -> Int -> T`

GHC chooses a representation based on the strictness etc.

tcName :: NameSpace Source

clsName :: NameSpace Source

tcClsName :: NameSpace Source

dataName :: NameSpace Source

varName :: NameSpace Source

tvName :: NameSpace Source

srcDataName :: NameSpace Source

## Pretty Printing

pprNameSpace :: NameSpace -> SDoc Source

pprNonVarNameSpace :: NameSpace -> SDoc Source

pprNameSpaceBrief :: NameSpace -> SDoc Source

# The `OccName` type

data OccName Source

Instances

Eq OccName |
Data OccName |
Ord OccName |
Typeable OccName |
Outputable OccName |
Uniquable OccName |
Binary OccName |

pprOccName :: OccName -> SDoc Source

## Construction

mkOccName :: NameSpace -> String -> OccName Source

mkOccNameFS :: NameSpace -> FastString -> OccName Source

mkVarOcc :: String -> OccName Source

mkVarOccFS :: FastString -> OccName Source

mkDataOcc :: String -> OccName Source

mkDataOccFS :: FastString -> OccName Source

mkTyVarOcc :: String -> OccName Source

mkTyVarOccFS :: FastString -> OccName Source

mkTcOcc :: String -> OccName Source

mkTcOccFS :: FastString -> OccName Source

mkClsOcc :: String -> OccName Source

mkClsOccFS :: FastString -> OccName Source

mkDFunOccSource

Arguments

:: String | Typically the class and type glommed together e.g. `OrdMaybe`. Only used in debug mode, for extra clarity
-> Bool | Is this a hs-boot instance DFun?
-> OccSet | avoid these Occs
-> OccName | E.g. `$f3OrdMaybe`

mkTupleOcc :: NameSpace -> Boxity -> Arity -> OccName Source

setOccNameSpace :: NameSpace -> OccName -> OccName Source

## Derived `OccName`s

isDerivedOccName :: OccName -> Bool Source

mkDataConWrapperOcc :: OccName -> OccName Source

mkWorkerOcc :: OccName -> OccName Source

mkDefaultMethodOcc :: OccName -> OccName Source

mkDerivedTyConOcc :: OccName -> OccName Source

mkNewTyCoOcc :: OccName -> OccName Source

mkClassOpAuxOcc :: OccName -> OccName Source

mkCon2TagOcc :: OccName -> OccName Source

mkTag2ConOcc :: OccName -> OccName Source

mkMaxTagOcc :: OccName -> OccName Source

mkClassTyConOcc :: OccName -> OccName Source

mkClassDataConOcc :: OccName -> OccName Source

mkDictOcc :: OccName -> OccName Source

mkIPOcc :: OccName -> OccName Source

mkSpecOcc :: OccName -> OccName Source

mkForeignExportOcc :: OccName -> OccName Source

mkGenOcc1 :: OccName -> OccName Source

mkGenOcc2 :: OccName -> OccName Source

mkDataTOcc :: OccName -> OccName Source

mkDataCOcc :: OccName -> OccName Source

mkDataConWorkerOcc :: OccName -> OccName Source

mkSuperDictSelOccSource

Arguments

:: Int | Index of superclass, e.g. 3
-> OccName | Class, e.g. `Ord`
-> OccName | Derived `Occname`, e.g. `$p3Ord`

mkLocalOccSource

Arguments

:: Unique | Unique to combine with the `OccName`
-> OccName | Local name, e.g. `sat`
-> OccName | Nice unique version, e.g. `$L23sat`

mkMethodOcc :: OccName -> OccName Source

mkInstTyTcOccSource

Arguments

:: String | Family name, e.g. `Map`
-> OccSet | avoid these Occs

-> OccName

    R:Map

Derive a name for the representation type constructor of a `data`/`newtype` instance.

mkInstTyCoOcc :: OccName -> OccName Source

mkEqPredCoOcc :: OccName -> OccName Source

mkVectOcc :: OccName -> OccName Source

mkVectTyConOcc :: OccName -> OccName Source

mkVectDataConOcc :: OccName -> OccName Source

mkVectIsoOcc :: OccName -> OccName Source

mkPDataTyConOcc :: OccName -> OccName Source

mkPDataDataConOcc :: OccName -> OccName Source

mkPReprTyConOcc :: OccName -> OccName Source

mkPADFunOcc :: OccName -> OccName Source

## Deconstruction

occNameFS :: OccName -> FastString Source

occNameString :: OccName -> String Source

occNameSpace :: OccName -> NameSpace Source

isVarOcc :: OccName -> Bool Source

isTvOcc :: OccName -> Bool Source

isTcOcc :: OccName -> Bool Source

isDataOcc :: OccName -> Bool Source

isDataSymOcc :: OccName -> Bool Source

Test if the `OccName` is a data constructor that starts with a symbol (e.g. `:`, or `[]`)

isSymOcc :: OccName -> Bool Source

Test if the `OccName` is that for any operator (whether it is a data constructor or variable or whatever)

isValOcc :: OccName -> Bool Source

Value `OccNames`s are those that are either in the variable or data constructor namespaces

parenSymOcc :: OccName -> SDoc -> SDoc Source

Wrap parens around an operator

startsWithUnderscore :: OccName -> Bool Source

Haskell 98 encourages compilers to suppress warnings about unsed names in a pattern if they start with `_`: this implements that test

isTcClsNameSpace :: NameSpace -> Bool Source

isTvNameSpace :: NameSpace -> Bool Source

isDataConNameSpace :: NameSpace -> Bool Source

isVarNameSpace :: NameSpace -> Bool Source

isValNameSpace :: NameSpace -> Bool Source

isTupleOcc_maybe :: OccName -> Maybe (NameSpace, Boxity, Arity)Source

# The `OccEnv` type

data OccEnv a Source

Instances

Outputable a => Outputable (OccEnv a) |

emptyOccEnv :: OccEnv aSource

unitOccEnv :: OccName -> a -> OccEnv aSource

extendOccEnv :: OccEnv a -> OccName -> a -> OccEnv aSource

mapOccEnv :: (a -> b) -> OccEnv a -> OccEnv bSource

lookupOccEnv :: OccEnv a -> OccName -> Maybe aSource

mkOccEnv :: [(OccName, a)] -> OccEnv aSource

mkOccEnv_C :: (a -> a -> a) -> [(OccName, a)] -> OccEnv aSource

extendOccEnvList :: OccEnv a -> [(OccName, a)] -> OccEnv aSource

elemOccEnv :: OccName -> OccEnv a -> Bool Source

occEnvElts :: OccEnv a -> [a]Source

foldOccEnv :: (a -> b -> b) -> b -> OccEnv a -> bSource

plusOccEnv :: OccEnv a -> OccEnv a -> OccEnv aSource

plusOccEnv_C :: (a -> a -> a) -> OccEnv a -> OccEnv a -> OccEnv aSource

extendOccEnv_C :: (a -> a -> a) -> OccEnv a -> OccName -> a -> OccEnv aSource

extendOccEnv_Acc :: (a -> b -> b) -> (a -> b) -> OccEnv b -> OccName -> a -> OccEnv bSource

filterOccEnv :: (elt -> Bool) -> OccEnv elt -> OccEnv eltSource

delListFromOccEnv :: OccEnv a -> [OccName] -> OccEnv aSource

delFromOccEnv :: OccEnv a -> OccName -> OccEnv aSource

# The `OccSet` type

type OccSet = UniqSet OccName Source

emptyOccSet :: OccSet Source

unitOccSet :: OccName -> OccSet Source

mkOccSet :: [OccName] -> OccSet Source

extendOccSet :: OccSet -> OccName -> OccSet Source

extendOccSetList :: OccSet -> [OccName] -> OccSet Source

unionOccSets :: OccSet -> OccSet -> OccSet Source

unionManyOccSets :: [OccSet] -> OccSet Source

minusOccSet :: OccSet -> OccSet -> OccSet Source

elemOccSet :: OccName -> OccSet -> Bool Source

occSetElts :: OccSet -> [OccName]Source

foldOccSet :: (OccName -> b -> b) -> b -> OccSet -> bSource

isEmptyOccSet :: OccSet -> Bool Source

intersectOccSet :: OccSet -> OccSet -> OccSet Source

intersectsOccSet :: OccSet -> OccSet -> Bool Source

# Tidying up

type TidyOccEnv = OccEnv Int Source

emptyTidyOccEnv :: TidyOccEnv Source

tidyOccName :: TidyOccEnv -> OccName -> (TidyOccEnv, OccName)Source

initTidyOccEnv :: [OccName] -> TidyOccEnv Source

# Lexical characteristics of Haskell names

isLexCon :: FastString -> Bool Source

isLexVar :: FastString -> Bool Source

isLexId :: FastString -> Bool Source

isLexSym :: FastString -> Bool Source

isLexConId :: FastString -> Bool Source

isLexConSym :: FastString -> Bool Source

isLexVarId :: FastString -> Bool Source

isLexVarSym :: FastString -> Bool Source

startsVarSym :: Char -> Bool Source

startsVarId :: Char -> Bool Source

startsConSym :: Char -> Bool Source

startsConId :: Char -> Bool Source