|
|
# `RdrNames`, `Modules`, and `OccNames`
|
|
|
|
|
|
|
|
|
When the parser parses an identifier, it generates a `RdrName`. A `RdrName` is pretty much just a string, or a pair of strings, for a qualified name, such as `M.x`. Here's the data type declaration, from [compiler/basicTypes/RdrName.hs](https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/basicTypes/RdrName.hs):
|
|
|
When the parser parses an identifier, it generates a `RdrName`. A `RdrName` is pretty much just a string, or a pair of strings, for a qualified name, such as `M.x`. Here's the data type declaration, from [compiler/GHC/Types/Name/Reader.hs](https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/GHC/Types/Name/Reader.hs):
|
|
|
|
|
|
```wiki
|
|
|
data RdrName
|
... | ... | @@ -34,7 +34,7 @@ For example, code generated by `deriving` might use an `Orig` to refer to `Prelu |
|
|
## The `Module` and `ModuleName` types
|
|
|
|
|
|
|
|
|
In GHC, a *module* is uniquely defined by a pair of the module name and the package where the module is defined. The details are in [compiler/basicTypes/Module.hs](https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/basicTypes/Module.hs) and [compiler/main/PackageConfig.hs](https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/main/PackageConfig.hs), but here are the key definitions:
|
|
|
In GHC, a *module* is uniquely defined by a pair of the module name and the package where the module is defined. The details are in [compiler/GHC/Types/Module.hs](https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/GHC/Types/Module.hs) and [compiler/main/UnitInfo.hs](https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/main/UnitInfo.hs), but here are the key definitions:
|
|
|
|
|
|
```wiki
|
|
|
newtype PackageId = PId FastString
|
... | ... | @@ -54,7 +54,7 @@ You'll notice that a `Qual` `RdrName` contains a `ModuleName`; which module is r |
|
|
|
|
|
|
|
|
An `OccName` is more-or-less just a string, like "foo" or "Tree", giving the (unqualified) name of an entity.
|
|
|
Well, not quite just a string, because in Haskell a name like "C" could mean a type constructor or data constructor, depending on context. So GHC defines a type `OccName` that is a pair of a `FastString` and a `NameSpace` indicating which name space the name is drawn from. The data type is defined (abstractly) in [compiler/basicTypes/OccName.hs](https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/basicTypes/OccName.hs):
|
|
|
Well, not quite just a string, because in Haskell a name like "C" could mean a type constructor or data constructor, depending on context. So GHC defines a type `OccName` that is a pair of a `FastString` and a `NameSpace` indicating which name space the name is drawn from. The data type is defined (abstractly) in [compiler/GHC/Types/Name/Occurrence.hs](https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/GHC/Types/Name/Occurrence.hs):
|
|
|
|
|
|
```wiki
|
|
|
data OccName = OccName
|
... | ... | |