1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
4 <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
5 <title>The GHC Commentary - The Real Story about Variables, Ids, TyVars, and the like</title>
8 <body BGCOLOR="FFFFFF">
9 <h1>The GHC Commentary - The Glorious Renamer</h1>
12 (This section is, like most of the Commentary, rather incomplete.)
14 The <em>renamer</em> sits between the parser and the typechecker.
15 Roughly speaking, It has the type:
17 HsModule RdrName -> HsModule Name
19 That is, it converts all the <tt>RdrNames</tt> to <a href="names.html"><tt>Names</tt></a>.
23 A <tt>RdrNames</tt> is pretty much just a string (for an unqualified name
24 like "<tt>f</tt>") or a pair of strings (for a qualified name like "<tt>M.f</tt>"):
26 data RdrName = RdrName Qual OccName
30 | Qual ModuleName -- A qualified name written by the user in source code
31 -- The module isn't necessarily the module where
32 -- the thing is defined; just the one from which it
35 | Orig ModuleName -- This is an *original* name; the module is the place
36 -- where the thing was defined
38 The OccName type is described in <a href="names.html#occname">"The truth about names"</a>.
40 The <tt>OrigName</tt> variant is used internally; it allows GHC to speak of <tt>RdrNames</tt>
41 that refer to the original name of the thing.
44 <h2> Rebindable syntax </h2>
46 In Haskell when one writes "3" one gets "fromInteger 3", where
47 "fromInteger" comes from the Prelude (regardless of whether the
48 Prelude is in scope). If you want to completely redefine numbers,
49 that becomes inconvenient. So GHC lets you say
50 "-fno-implicit-prelude"; in that case, the "fromInteger" comes from
51 whatever is in scope. (This is documented in the User Guide.)
53 This feature is implemented as follows (I always forget).
55 <li> Four HsSyn constructs (NegApp, NPlusKPat, HsIntegral, HsFractional)
56 contain a <tt>Name</tt> (i.e. it is not parameterised).
57 <li> When the parser builds these constructs, it puts in the built-in Prelude
58 Name (e.g. PrelNum.fromInteger).
59 <li> When the renamer encounters these constructs, it calls <tt>RnEnv.lookupSyntaxName</tt>.
60 This checks for <tt>-fno-implicit-prelude</tt>; if not, it just returns the same Name;
61 otherwise it takes the occurrence name of the Name, turns it into an unqualified RdrName, and looks
62 it up in the environment. The returned name is plugged back into the construct.
63 <li> The typechecker uses the Name to generate the appropriate typing constraints.
67 Last modified: Tue Nov 13 14:11:35 EST 2001