[erlang-questions] Parameterized module initialization

Joe Armstrong erlang@REDACTED
Thu Jun 28 11:03:46 CEST 2012

On Thu, Jun 28, 2012 at 1:24 AM, Robert Virding
<robert.virding@REDACTED> wrote:
> I quite agree. Having finally got rid of {M,F} please,please,please don't replace it with something even worse. I am no great fan of parametrised modules but if they are to be properly added to the language then do it as an opaque data type and use the module:new function to initialise it.

But it's not worse. The "sneaky" mechanism has the additional advantages over
paramterised module:

   1) Variables in the body of a function "appear by magic" - ie they are not
        declared in the head of the function. So I can't just cut and
paste code from
        one module to another.
   2) You can only have one "new" constructor (I am correct here)
        suppose I have one group of function in a module that need access to
        module parameter variables A,B,C and some other set of functions needs
       different variables P,Q,R - If I understand correctly this can't be done
       (this should be solved by a letrec, but that's a different discussion)
    3) This provides a very convenient syntax for the user of a module
         X:some_function(...) is very familiar to users of other programming
        languages (like Javascript) - the idea that X contains some state is
        "normal" for most programmers coming to Erlang from other languages


> Otherwise we might as well open up funs as well so we can really have fun.*
> Robert
> * that was being sarcastic.
> ----- Original Message -----
>> Hi,
>> On Tue, Jun 26, 2012 at 2:53 PM, Joe Armstrong <erlang@REDACTED>
>> wrote:
>> > There is an undocumented way of doing this (which one day will
>> > become standard)
>> > Suppose we define X as follows:
>> >> X = {mod1, a,b,c}.
>> > {mod1, a,b,c}.
>> > X is now an instance of a parameterised module. if we now call the
>> > function X:func1(x,y) then what actually gets called is the
>> > function
>> > mod1:func1(x,y,{mod1,a,b,c})
>> I hope that you are expressing some form of sarcasm, Joe.
>> If I may use such language, it is horrible. Just as we got (almost)
>> rid of {M,F} to the benefit of proper function references, are we
>> going to get another kludge? A proper module reference is the way to
>> go here. Then there are plenty of nice things that can be supported
>> in
>> a clean way.
>> best regards,
>> Vlad
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions

More information about the erlang-questions mailing list