[erlang-questions] Modules and function "encapsulation"

Richard O'Keefe ok@REDACTED
Mon Sep 6 00:02:51 CEST 2010


On Sep 1, 2010, at 6:33 PM, Ulf Wiger wrote:
> The EUC talk mentioned, by Richard Carlsson, has been implemented as
> an experimental feature. http://www.trapexit.org/Extend_Module
> 
> Note the experimental status. This is not to say it doesn't work -
> I daresay it does - but that there is no commitment to keep the
> feature as-is.

I read the slides, but I'm afraid they are rather vague.
Is there a more precise specification anywhere?

At first blush, this does nothing that
 - (1) explicitly importing the base module's exports into
       the extension module, and
 - (2) allowing the extension module to re-export imported
       functions
would not do.  The only problem with doing it that way is
that the Erlang compiler won't LET you:
% cat -n foo.erl
     1  -module(foo).
     2  -import(bar, [ugh/1]).
     3  -export([ugh/1, zoo/2]).
     4  
     5  zoo(X, Y) -> ugh(X+Y).
     6  
% erlc foo.erl
./foo.erl:3: function ugh/1 undefined

Relaxing this apparently pointless restriction would be a far
simpler change to the language than adding -extends; it would
provide a very very simple way for a module to extend MANY
modules; and it would be much better than -extends because it
would be EXPLICIT.  As it stands, -extends(bar) says
"I don't know and I don't care what bar exports.
 I trust bar TOTALLY.
 Whatever bar exports, today, tomorrow, or until the Sun
 goes out, I export that too."
That really does not seem to be in the spirit of Erlang to me.

So I must have misunderstood the proposal.

  


More information about the erlang-questions mailing list