cca29322ecb047bc5409b197a96d21274e33af5c
[ghc-hetmet.git] / ghc / docs / NOTES.rename
1
2
3
4 Questions concerning the meaning of hiding in certain contexts:
5
6 1) Suppose we have the interface
7    interface A where
8    data T = B | C
9
10    and the module
11    module H where
12    import A hiding T
13
14    Should this be an error (because T isn't an abstract type in the module)
15    or does it just mean the same thing as would 
16    import A hiding (T (B,C))
17    or
18    import A hiding (T (..))
19    (in other words, hide all of T)
20    Will require the user to be precise and flag it as an error - otherwise
21    the user may not know that the type is not abstract, thinking that it is.
22
23 2) Clearly, we can't allow (assuming the interface above)
24    module H where
25    import A hiding (T (B))
26
27    since that means that a data type with a subset of the constructors is
28    exported - similarly for classes
29
30 3) Suppose an interface exports an abstract type H. Can H be referred
31    to as H (..), or is that an error? Let's require precision and call it
32    an error.
33
34 --------------- new design for renamer -------------------
35
36 Changes to abstract syntax
37
38 1) ClsSigs becomes Sigs
39
40 2) Instances need new syntax (bool) distinguishing between those which
41 come from an interface and those which come from a module. 
42
43 The renamer is factored into four passes, as follows:
44
45 1) FLATTEN INTERFACES -
46    insert original names into interfaces. All of the decls imported
47    from the interfaces are collected and returned, in an otherwise
48    unchanged module. No interfaces exist after this pass.
49
50 2) Do consistency checks (equality). Return the module including the surviving declarations.
51
52 3) build the global name function, which will maintain two separate
53    namespaces.
54
55 4) assign names to the entire module, and do dependency analysis.
56
57 As the prelude environments will yield names, the first pass will replace
58 QuickStrings with constructors of the ProtoName type, defined as
59
60 data ProtoName = Unknown QuickString
61                         -- note that this is the name local to the module
62                | Imported QuickString QuickString QuickString
63                | Prelude Name
64
65 The parser will initially make all QuickStrings Unknown.
66
67 Modules must now include signatures for value decls at top level.
68
69 The entire set of passes have the following types:
70
71 type PrelNameFuns = (GlobalNameFun, GlobalNameFun)
72
73 type GlobalNameFun = ProtoName -> Maybe Name
74
75 renameModule :: PrelNameFuns -> ProtoNameModule -> RenameMonad RenamedModule
76
77 renameModule1 :: PrelNameFuns -> ProtoNameModule -> RenameMonad ProtoNameModule
78
79 processModImports1 :: PrelNameFuns -> ProtoNameImportDecls 
80                         -> RenameMonad (ProtoNameFixityDecls, ProtoNameTyDecls, 
81                                         ProtoNameClassDecls, ProtoNameInstDecls, 
82                                         ProtoNameSigDecls)
83
84 renameModule2 :: ProtoNameModule -> RenameMonad ProtoNameModule
85
86 renameModule3 :: PrelNameFuns -> ProtoNameModule -> GlobalNameFun
87
88 renameModule4 ::  GlobalNameFun -> ProtoNameModule -> RenameMonad RenamedModule
89
90 renameModule :: PrelNameFuns -> ProtoNameModule -> RenameMonad RenamedModule
91 renameModule pnf mod 
92  = (renameModule1 pnf mod)      `thenRenameM` (\ mod_with_orig_interfaces ->
93    (renameModule2 mod_with_orig_interfaces) 
94                          `thenRenameM` (\ mod_minus_interfaces ->
95    (renameModule3 pnf mod_minus_interfaces)
96                          `thenRenameM` (\ global_name_fun ->
97    (renameModule4 mod_minus_interfaces global_name_fun))))
98
99 Namespace confusion: According to the report (1.1), `An identifier must
100 not be used as the name of a type constructor and a class in the same 
101 scope.' This is apparently the only constraint on the namespace, other
102 than those implied by the conventions for identifiers. So, what are the
103 namespaces? 
104
105 1) variables and class operations, constructors
106
107 2) type constructors and classes (because of the statement above)
108
109