[erlang-questions] Why do we need modules at all?

Kresten Krab Thorup <>
Tue May 24 11:05:03 CEST 2011


Sorry, my mail got strangled in flight.  Here we go again... in plain text.

The gen_server module is used for three different things:

- as a collection of API function (left)
- a place to put the code that controls the gen_server process (middle)
- a place to describe the abstract notion of a gen_server behavior (right).

Ideally, I think those three usages should be separate language constructs, but probably not in separate files (or other kinds of units).

When using a gen_server, it would be nice if you did not have to expose the behavior api to the "user" of your module.


Currently, the module is the unit of code loading.  I think we could use a bette mechanism, perhaps one that supports an STM-like thing in the VM to control the loading of a set of modules.  I don't have much deep experience with code loading in Erlang (but do have it on Java), and it just seems to me that being able to control atomic loading of .. say a new version of an Erlang application would be good to have supported in the VM.


Gilad Bracha (who's working on Newspeak) has an excellent blog on new notions of modues that you should read.  You can start here http://gbracha.blogspot.com/2009/06/ban-on-imports.html

One of the things he's arguing is that modules should be VALUES.  A "module" in newspeak is kind of a template (function), which take other module instances as arguments.  So you hook up a system by applying such templates (possibly using letrec).  


If we had a visual programming environment, then many things don't need a name.  Self is an example of this (Self, the video: http://video.google.com/videoplay?docid=5776880551404953752#)  

Kresten




More information about the erlang-questions mailing list