Scope of imported names

Iavor S. Diatchki diatchki@cse.ogi.edu
Tue, 23 Oct 2001 09:49:51 -0700


hello

> > from module M (module M) where { ... }
> 
> That's right (this refers to section 5.2, fifth numbered item). What is
> the rationale behind requiring the qualified name to be visible also?

i think the idea is that when one writes "module M" in an export list,
they probably mean export the entities of "M".  the question is what
are the entities of "M"?  there are a few possible choices, here are
some:
1. entities defined in module M (which are currently in scope?)
2. entities imported from module M
3. entities which may be reffered to as M.f(for some unqualified name f)

1) is probably the simplest, but doesnt seem to fit well with the
haskell module system as modules may export entities, which they didnt
define.   this makes it difficult for a programmer to work out what
will "module M" actually export.

2) is probably quite a reasonable choice, but doesnt seem to go well
with the aliasing feature of the haskell module system. for example,
given the import: "import X as Y"
and if the programmer wanted to export a single entity "f",
which came thru' this import they could write "Y.f", but if they wanted
to export all such entities they would have to write "module X", and
this seems awkward.

3) is (kind of) what the report currently chooses, going with the idea
that if somthing may be called "M.f", it somehow belongs to "M", which
i think is the rationale behind the requirement of qualified names
to be inscope.

there is an additional requirement however, which is probably not as intuitive.
it states that the unqualified name (i.e. "f") must be inscope as well
(and refer to the same thing).  i think the reason for this is to
avoid some clashes in exports.  here is a motivating example,
someone posted a few weeks ago:

module A (f, module B) where
import B hiding (f)
import qualified B(f) 

f = ...

this essentially provides a module, which is the same as B, execpt that
it replaces the "f" function. if it wasnt for the extra condition, 
theer would be an export clash, as the name "f" may refer to either
to the "f" defined in A, or the one imported from B.

hope this helps.

bye
iavor

-- 
==================================================
| Iavor S. Diatchki, Ph.D. student               | 
| Department of Computer Science and Engineering |
| School of OGI at OHSU                          |
| http://www.cse.ogi.edu/~diatchki               |
==================================================