X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=docs%2Fcomm%2Fthe-beast%2Fnames.html;fp=docs%2Fcomm%2Fthe-beast%2Fnames.html;h=061fae3ebfefe2723ba101993bdfafd7ace1efc9;hp=0000000000000000000000000000000000000000;hb=0065d5ab628975892cea1ec7303f968c3338cbe1;hpb=28a464a75e14cece5db40f2765a29348273ff2d2 diff --git a/docs/comm/the-beast/names.html b/docs/comm/the-beast/names.html new file mode 100644 index 0000000..061fae3 --- /dev/null +++ b/docs/comm/the-beast/names.html @@ -0,0 +1,169 @@ + + + + + The GHC Commentary - The truth about names: OccNames, and Names + + + +

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 four flavours of Name: +

+
+
+data NameSort
+  = External Module (Maybe Name)
+	-- (Just parent) => this Name is a subordinate name of 'parent'
+	-- e.g. data constructor of a data type, method of a class
+	-- Nothing => not a subordinate
+ 
+  | WiredIn Module (Maybe Name) TyThing BuiltInSyntax
+	-- A variant of External, for wired-in things
+
+  | Internal		-- A user-defined Id or TyVar
+			-- defined in the module being compiled
+
+  | System		-- A system-defined Id or TyVar.  Typically the
+			-- OccName is very uninformative (like 's')
+
+ + +

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: Wed May 4 14:57:55 EST 2005 + + + + +