Proposal: module namespaces.

Christian Brolin
Wed, 28 Feb 2001 09:49:25 +0100

Malcolm Wallace wrote:
> Christian writes:
> > What about the module declaration? Should it be:
> >   module Text.Xml.Parser where ...
> > or just
> >   module Parser where ...  -- located in Text/Xml/Parser.hs?
> The former.  The reason is that a compiler needs to generate a unique
> linker symbol for each defined function.  If the full module name is
> not encoded in the source file, you will need to add a commandline
> option to the compiler, which is the wrong way to go in my opinion.

What?? The compiler knows the full name of the module without the module
clause. If it didn't do that, it can't find the modules to compile! Does
the compiler opens every file on the Internet to check whether it is the
file to compile? How does the compiler find the file to compile in the
first place? What should the command line option you mentioned do?

> Why is  e.g. Parser.f  not sufficient as a unique symbol for
> Text.Xml.Parser.f?  Well, what if you also have Text.Html.Parser.f?
> You really need the full thing.

Of course, see above.

> > I would also like to import modules using relative addresses, e.g. the
> > file:
> >   My/Small/Test/Xml/Parser.hs
> > contains:
> >   import .Lexer  -- Relative path to the module: My.Small.Test.Xml.Lexer
> >   import ..Data  -- Relative path to the module: My.Small.Test.Xml.Parser.Data
> >   import Text.ParserCombinators.HuttonMeijer  -- Absolute address
> I'm sorry, I don't entirely follow what the differing numbers of
> initial dots mean.

They are used to specify relative addresses to other modules. Relative
addresses is a very important concept, but You missed it in your

The dots was just my suggestion of a syntax for relative addresses. 
One dot: Relative to the parent of this module.
Two dots: Relative to this module.

module A.B.C.D1 where
import A.B.C.D1.E1
import A.B.C.D1.E1.F
import A.B.C.D1.E2
import A.B.C.D2
import X.Y.Z

would be the same as (delete 'A.B.C'):
module A.B.C.D1 where
import .D1.E1
import .D1.E1.F
import .D1.E2
import .D2
import X.Y.Z

would be the same as (delete 'D1'):
module A.B.C.D1 where
import ..E1
import ..E1.F
import ..E2
import .D2
import X.Y.Z

Move the package of modules (A.B.C.*) to (Std.AAA.BBB.CCC.*) and rename
D1 to DDD:
module Std.AAA.BBB.CCC.DDD where
import ..E1
import ..E1.F
import ..E2
import .D2
import X.Y.Z

The only thing that needs to be changed is the module clause. Which of
course would be unnecessary if the module clause was dropped.

> > When the world realize that this is the XML parser, they won't accept
> > the name and I refuse to change my implementation. The only thing that
> > is needed to rename (an unused) module hierarchy is to move it.
> If you refuse to change your implementation, someone else will change
> it for you!  You can't have closed standards.

It is not necessary to modify the modules if the module system supports
relative addresses!!! The steering wheel of my car is positioned
relative to my car, so it is NOT necessary to change that position when
I move the car.

Christian Brolin