[erlang-questions] Re: Parameterized module idioms
Richard O'Keefe
ok@REDACTED
Mon Apr 19 05:20:37 CEST 2010
On Apr 18, 2010, at 9:28 AM, Jayson Vantuyl wrote:
>> For example, [unless you're doing some crazy rewriting tricks] it's
>> obvious which function this is calling:
>>
>> some_module:echo(E, "hello")
>>
>> This isn't so obvious:
>>
>> E:echo("hello")
>>
>> Here you have to trace back to the definition of E to find out what
>> module it refers to.
> Actually, that's the point. There are two good reasons to do this.
>
> 1. Hide massive amounts of information.
We can already do this with plain old closures.
Instead of
E:echo("hello")
we can do
E(echo, "hello")
To a first approximation, any module with parameters can be written
as a function that returns a closure (the standard OO-in-FP trick).
>
> 2. Polymorphism
Also trivially doable with plain old closures.
More information about the erlang-questions
mailing list