[erlang-questions] Multiple modules

Daniel Goertzen <>
Sun Oct 8 01:11:35 CEST 2006


That starts to strongly resemble the way C++ namespaces work.

Using the mnesia app as an example, the app source files are well 
decomposed into their functional areas, for example: mnesia_subscr.erl, 
mnesia_controller.erl, mnesia_checkpoint.erl, etc.  But the entire API 
for mnesia is really exported through the module "mnesia", and 
mnesia.erl contains lots of functions that just relay calls to other 
modules.  Wouldn't it make more sense for each of the files (ex, 
mnesia_subscr.erl) to be able to directly export bits and pieces into 
the mnesia module/namespace?

And this leads to the question of nested modules like C++ nested 
namespaces.  I've found that nested namespaces in C++ have helped me 
keep names short and natural and remove concern over collisions.  
Consider this erlang example:

Erlang makes me name stuff like this...

myapp:foo_dostuff(...)
myapp:bar_dostuff(...)


When I'd really like to say it like this...

myapp:foo:dostuff(...)
myapp:bar:dostuff(...)


Disclaimer:  I've written large c++ programs, but not any large elrang 
programs yet.  Please correct me if I've missed out on some erlang feature.

Cheers,
Dan.


Costel Vrinceanu wrote:
> If we separate files from modules/make them orthogonal, then it should
> work both ways:
>   N modules in 1 file
> or
>   1 module in N files
> or
>   N modules in M files
>
> On 10/5/06, Joe Armstrong <> wrote:
>   
>> Modules ... thoughts
>>
>> Any opinion about and "endmod." declaration:
>>
>> Proposal
>>
>> The file myapp.erl might contain
>>
>>   -module(foo).
>>   ....
>>   ....
>>   -endmod.
>>
>>   -module(bar).
>>    ...
>>   ...
>>   -endmod.
>>
>> Compiling this produces
>>
>> myapp.beam
>>
>> loading myapp.beam loads all the code in foo, bar, ..., this
>> has several advantages:
>>
>>     1) distribute only one file
>>     2) modules in file cannot live a life of their own and become
>>        separated
>>     3) code loading is faster
>>
>> /Joe
>>
>>
>>
>> _______________________________________________
>> erlang-questions mailing list
>> 
>> http://www.erlang.org/mailman/listinfo/erlang-questions
>>
>>
>>
>>     
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
>
>   




More information about the erlang-questions mailing list