[erlang-questions] Parameterized module idioms

Bob Ippolito bob@REDACTED
Mon Apr 19 05:43:53 CEST 2010


On Sunday, April 18, 2010, Richard O'Keefe <ok@REDACTED> wrote:
>
> 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.

Trivial, but requires a lot of boilerplate code and certainly isn't
any easier to understand or debug than parameterized modules. It also
becomes impossible to write a useful type spec if you use closures
like that.

-bob


More information about the erlang-questions mailing list