9

http://www.erlang.org/news/35 mentioned that this will be documented, but I can't find it in the documentation.

legoscia
  • 39,593
  • 22
  • 116
  • 167
rongtou
  • 93
  • 4

1 Answers1

12

A "tuple module" is a tuple with two elements, the name of a module and a list of extra arguments. For example:

{my_module, [foo, bar]}

Such a tuple can be used instead of a module name in function calls. In this case, the function being called will get the tuple in question as an additional argument at the end of the argument list:

3> Module = {lists, [[foo]]}.
{lists,[[foo]]}
4> Module:append([bar]).
[bar|{lists,[[foo]]}]

This call is equivalent to:

7> lists:append([bar], {lists, [[foo]]}).
[bar|{lists,[[foo]]}]

Tuple modules are kept for backwards compatibility, as they were the implementation mechanism for parameterised modules, which were removed from the language in R16.

Community
  • 1
  • 1
legoscia
  • 39,593
  • 22
  • 116
  • 167
  • 2
    hum, I was expecting [foo, bar] as the end result – Isac Jun 06 '13 at 14:28
  • 1
    Me too, thus my choice of function for testing :) – legoscia Jun 06 '13 at 14:43
  • 1
    Attention for example! Standard library not suit for this calling, because last argument alwasy the whole tuple with module qualification, which not expected by std modules as `lists` etc. Arguments not extracted for compiler consider arity. This can be useful with new modules like this: https://github.com/comtihon/mongodb-erlang. – DenisKolodin Sep 03 '15 at 13:28