[erlang-questions] Parameterized module idioms
Sat Apr 17 03:04:58 CEST 2010
On Fri, Apr 16, 2010 at 5:13 PM, Fred Hebert <> wrote:
> On Fri, Apr 16, 2010 at 8:06 PM, Bob Ippolito <> wrote:
>> Technically speaking the difference is:
>> E:echo("hello") vs. some_module:echo(E, "hello")
>> The biggest reason I've seen to use parameterized modules is that you
>> could have a different module that implements the same interface, e.g.
>> sets and gb_sets and you could change which one you're using without
>> changing any of the code that consumes it.
>> I would definitely change the original code to use two modules, one
>> module to do the start_link stuff, and another module to actually
>> implement the interface.
> M = sets,
> D = M:new().
> M:add_element(10, D).
> This works as well without a problem. Switch the value of M and if the
> interface is the same, nothing changes.
Yes, but now you're passing around two variables instead of one.
More information about the erlang-questions