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?
Tuple Tuples are used to store multiple items in a single variable. Tuple is one of 4 built-in data types in Python used to store collections of data, the other 3 are List, Set, and Dictionary, all with different qualities and usage. A tuple is a collection which is ordered and unchangeable.
The number and elements of a tuple are fixed at compile time and they cannot be changed at run time. Tuples have characteristics of both structs and arrays. The tuple elements can be of different types like structs. The elements can be accessed via indexing like arrays.
Sometimes, while working with records, we can have a problem in which we may need to perform modulo of tuples. This problem can occur in day-day programming. Let’s discuss certain ways in which this task can be performed.
If you are targeting an earlier version of .NET Framework, the compiler uses versions of System.Tuple from the 2.0 version of the F# Core Library. The types in this library are used only for applications that target the 2.0, 3.0, and 3.5 versions of .NET Framework.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With