Problem with hierarchical libraries.

Tanton Gibbs thgibbs@deltafarms.com
Fri, 7 Mar 2003 15:45:34 -0500


> > I know that we generally try to avoid specifying filename and directory
> > issues.
> > However, this is not really a filename issue, but a problem of relative
> > and absolute module names (wrt possibly several hierarchies). An "import
> > B" in module Test.A could mean either module B or module Test.B.
> > I suggest that the absolute module name takes precedence, because
> > otherwise there is no way to import module B from module Test.A, whereas
> > you can always import module Test.B from module Test.A by saying "import
> > Test.B".
>
> why not fix the design to take this into account?  one can have two ways
> to refer to modules - relative and absolute (just like in the file
> system, which years of experience show works pretty well).
>
> import .Test.A  -- refers to an absolute path
>                  -- (relative to a user specified root)
>                  -- i.e. $HS_PATH/Test/A.hs
> import Test.A -- is a path relative to the location of
> -- the current module, i.e.
> -- [location of module]/Test/A.hs

An interesting idea, but I have two comments on it.  First, I think using a
. at the beginning of the
module name is not visual enough to be easily seen.  Something as important
as which module
to pick should have something that stands out as absolute or relative.
Second, I would prefer
it select relative offset modules before checking for absolute modules.  I
would imagine that
the designer of a module would want associated modules inserted more often
than those with
the same name but not associated with the current module. (Actually, the
second comment
is not on your post, but on the post you commented on).

> i also have another question about the hirarchical modules design -- why
> does one have to duplicate the path to a particular file inside the file
> itself?   i.e. what is the point of the module name within the file?
> it seems that all haskell implementations assume that the module name
> and file name are the same (and this seems perfectly reasonable), and
> with the hirarchical name space this is even more the case.  and for
> example C programers never specify the name of the current file within
> the file.  why do we want to do it?

Often, in C++ and Java, one has many modules in a file, but only one that is
meant to be visible to
the outside world.  Other modules might be name _ext_X or _private_X or
something along those lines.
By requiring a module name, you allow the primary module to start anywhere
in the file as well as other
modules to be defined in the file.  Furthermore, you allow files that don't
contain modules, something very
important for quick prototyping.

Thanks!
Tanton