Proposal: Scoping rule change
Heinrich Apfelmus
apfelmus at quantentunnel.de
Wed Jul 25 11:26:13 CEST 2012
Lennart Augustsson wrote:
> It's not often that one gets the chance to change something as
> fundamental as the scoping rules of a language. Nevertheless, I would
> like to propose a change to Haskell's scoping rules.
>
> The change is quite simple. As it is, top level entities in a module
> are in the same scope as all imported entities. I suggest that this
> is changed to that the entities from the module are in an inner scope
> and do not clash with imported identifiers.
>
> Why? Consider the following snippet
>
> module M where
> import I
> foo = True
I like it.
That said, how does the the fact that the scope is nested affect the
export list? If the module scope is inside the scope of the imports,
then this means the name I.foo should appear in the export list, not
foo , because the latter is in the outermost scope.
I think the solution to these problems is to rearrange the import
declarations so that the syntax mirrors the scoping rules. In other
words, I boldly propose to move the import declaration *before* the
module declaration, i.e.
import I
module M where
foo = True
or even
import I where
module M where
foo = True
This way, it is clear that the module M opens an inner scope and that
the export list of M uses the names from the inner scope.
Best regards,
Heinrich Apfelmus
--
http://apfelmus.nfshost.com
More information about the Haskell-prime
mailing list