[m-dev.] module system discussion

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Dec 12 05:05:42 AEDT 2001


On 12-Dec-2001, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> I took your first statement above to mean that instead of this:
> 
> 	:- module module1.
> 		:- module class1.
> 			:- typeclass class1 where ...
> 		:- end_module class1.
> 		:- module class2.
> 			:- typeclass class2 where ...
> 		:- end_module class2.
> 
> 		:- include_module module1__sub_module1.
> 		:- include_module module1__sub_module2.
> 	:- end_module module1.
> 
> you should write this:
> 
> 	:- module module1.
> 		:- module classes.
> 			:- module class1.
> 				:- typeclass class1 where ...
> 			:- end_module class1.
> 			:- module class2.
> 				:- typeclass class2 where ...
> 			:- end_module class2.
> 		:- end_module classes.
> 
> 		:- include_module module1__sub_module1.
> 		:- include_module module1__sub_module2.
> 	:- end_module module1.
> 
> So now you could import module1 and its classes (but not sub_module1
> and sub_module2) using
> 	:- import_module module1, module1__classes.
> 	:- use_hierarchy module1__classes.
> 
> where with transparent sub-modules you would just write
> 	:- import_module module1.
> 
> > So there's nothing extra to remember.
> 
> The `classes' module name is the extra thing to remember.
> 
> Maybe I misunderstood. 

I think _I_ misunderstood.  But the example helps -- I understand your
point now.

However, I'm still not convinced.  For this example,
I'd be happy to write it just like this:

 	:- module module1.
 		:- module classes.
 			:- typeclass class1 where ...
 			:- typeclass class2 where ...
 		:- end_module classes.
 
 		:- include_module module1__sub_module1.
 		:- include_module module1__sub_module2.
 	:- end_module module1.

> > If you really want to avoid those two issues, then the types and/or
> > type classes in question can be placed directly in the top-level module,
> > rather than in a (transparent or opaque) sub-module.
> 
> No, they can't be placed in the top-level module because of possible
> name clashes, which is why we started talking about putting them in
> sub-modules in the first place. 

But that only applies when you're generating these things automatically
as part of a foreign language interface.  If you're writing the module
by hand, you can just name the methods of the different type classes
so that they don't clash.

Even in the case of automatically-generated interface modules,
name clashes can be avoided using prefixes.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list