<div>It's not often that one gets the chance to change something as</div><div>fundamental as the scoping rules of a language. Nevertheless, I would</div><div>like to propose a change to Haskell's scoping rules.</div>
<div><br></div><div>The change is quite simple. As it is, top level entities in a module</div><div>are in the same scope as all imported entities. I suggest that this</div><div>is changed to that the entities from the module are in an inner scope</div>
<div>and do not clash with imported identifiers.</div><div><br></div><div>Why? Consider the following snippet</div><div><br></div><div> module M where</div><div> import I</div><div> foo = True</div><div><br></div>
<div>Assume this compiles. Now change the module I so it exports something</div><div>called foo. After this change the module M no longer compiles since</div><div>(under the current scoping rules) the imported foo clashes with the</div>
<div>foo in M.</div><div><br></div><div>Pros: Module compilation becomes more robust under library changes.</div><div>Fewer imports with hiding are necessary.</div><div><br></div><div>Cons: There's the chance that you happen to define a module identifier</div>
<div>with the same name as something imported. This will typically lead to</div><div>a type error, but there is a remote chance it could have the same</div><div>type.</div><div><br></div><div>Implementation status: The Mu compiler has used the scoping rule for</div>
<div>several years now and it works very well in practice.</div><div><br></div><div> -- Lennart</div><div><br></div>