The GHC Commentary - The truth about names: OccNames, and Names

Every entity (type constructor, class, identifier, type variable) has a Name. The Name type is pervasive in GHC, and is defined in basicTypes/Name.lhs. Here is what a Name looks like, though it is private to the Name module.

  data Name = Name {
		n_sort :: NameSort,	-- What sort of name it is
		n_occ  :: !OccName,	-- Its occurrence name
		n_uniq :: Unique,       -- Its identity
		n_loc  :: !SrcLoc	-- Definition site
	    }

The NameSort of a Name

There are three flavours of Name:
  data NameSort
    = External Module
    | Internal
    | System

Occurrence names: OccName

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 (defined in basicTypes/OccName.lhs) that is a pair of a FastString and a NameSpace indicating which name space the name is drawn from:
    data OccName = OccName NameSpace EncodedFS
The EncodedFS is a synonym for FastString indicating that the string is Z-encoded. (Details in OccName.lhs.) Z-encoding encodes funny characters like '%' and '$' into alphabetic characters, like "zp" and "zd", so that they can be used in object-file symbol tables without confusing linkers and suchlike.

The name spaces are:

Last modified: Tue Nov 13 14:11:35 EST 2001