Erlang Central

Parameterized Modules

From ErlangCentral Wiki

A convenience to passing around a set of values for a module one can use the hidden feature of parameterized modules. Proposed by Richard Carlsson in 'Inheritance in Erlang' and here. It works as follows.


-module(test, [A,B]).
-export([get_a/0, get_b/0]).

get_a() ->

get_b() ->


74> c(test).
75> test:module_info().
76> T = test:new("This is A", "This is B").
{test,"This is A","This is B"}
77> T:get_a().
"This is A"
78> T:get_b().
"This is B"
79> T:module_info().
** exception error: bad argument
     in function  erlang:get_module_info/2
        called as erlang:get_module_info(test,{test,"This is A","This is B"})
     in call from test:module_info/1
80> test:instance("A","B").

Related Concepts:

More info:

An sentence from

Dmitry Podkorytov

parametrized code are no longer supported