12

EDIT: Steve Vinoski kindly provided in the comments the official name for those : tuple modules.

My original question remains though: are tuple modules officially documented by the OTP team? And are they expected to remain supported in the future?


Original question:

Consider the following erlang module:

-module(foo).

-compile(export_all).

new(Bar) -> {foo, Bar}.

get({foo, Bar}) -> Bar.

I was quite amazed to see it allows the following (using erlang 19.1):

2> Foo = foo:new(bar).
{foo,bar}
3> Foo:get(). 
bar

which differs quite strongly from the usual way of calling a module's function.

As far as I can tell, it seems to be a remnant of parametrized modules, which have been deprecated since R16; and I can't find anything in the official documentation stating this is a supported, stable feature of the language.

My question is: is this a documented feature of the language? And if yes, where?

Steve Vinoski
  • 19,847
  • 3
  • 31
  • 46
user4867444
  • 244
  • 1
  • 7
  • Your `new/1` functions returns a "tuple module". See [this question](http://stackoverflow.com/questions/16960745/what-is-a-tuple-module-in-erlang) for more details. – Steve Vinoski Nov 11 '16 at 00:33
  • @SteveVinoski thanks! Also found [that other question](http://stackoverflow.com/questions/31954796/why-erlang-tuple-module-is-controversial) now that I know the right term for those. – user4867444 Nov 11 '16 at 01:03
  • @SteveVinoski I'm still not clear whether that's an officially document feature of the language though? Any take on that? – user4867444 Nov 11 '16 at 01:04
  • 2
    I'm not aware of, nor have I heard any discussion of, plans to get rid of them, so I assume they'll be around for at least a few more years, but then again I could be wrong since I don't know all the plans the OTP team has. Tuple modules are an official part of Erlang in the sense that the OTP team kept them intentionally so that systems previously using the experimental parameterized module feature could switch to them instead. – Steve Vinoski Nov 11 '16 at 01:28
  • Thanks. I guess that's the closest we'll get of an official statement on the subject :) – user4867444 Nov 11 '16 at 01:32
  • @SteveVinoski if you post an answer summing up the above, I'll be happy to accept it :) – user4867444 Nov 14 '16 at 02:19

1 Answers1

1

As far as I know this is an undocumented remnant of parameterized modules and exists to prevent legacy code from breaking. I imagine it is intended chiefly to prevent Mochiweb from breaking, as I can't think of any other serious libraries that make use of parameterized modules.

I can't locate any documentation on it and it doesn't seem to be a subject of current consideration. There was an announcement I cannot locate (but found references to, but not links) that claimed this would be documented, but that was quite a while ago.

The release readme for R16B where parameterized modules were removed mentions this:

OTP-10616

The experimental feature "parameterized modules" (also called "abstract modules") has been removed. For applications that depends on parameterized modules, there is a parse transform that can be used to still use parameterized modules.

The parse transform can be found at: github.com/erlang/pmod_transform

That issue number does not appear in OTP's issue tracker anymore, and I can't even find an occurrence of "parameterized module" or "tuple module" anywhere in OTP's Jira instance. So I'm assuming this is an undocumented legacy crutch and nothing more.

zxq9
  • 13,020
  • 1
  • 43
  • 60