[erlang-questions] Parameterized module idioms

Bob Ippolito <>
Tue Apr 20 00:46:36 CEST 2010

On Mon, Apr 19, 2010 at 3:25 PM, Richard O'Keefe <> wrote:
> I pointed out that modules with parameters give us nothing
> that plain old closures don't, in response to which
> On Apr 19, 2010, at 3:43 PM, Bob Ippolito wrote:
>> 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.
> (a) Such boilerplate code as is required can be automatically generated.
> (b) The possibility or otherwise of useful type specs depends on what
>    the type language allows.  Dependent type systems would have no
>    trouble at all; the question of _how much_ of the machinery of a
>    dependent type system one needs is an empirical matter.
> (c) A dismissal of closures on such grounds is ALSO a dismissal of
>    modules with parameters since each can simulate the other.

I was speaking practically, not theoretically. The current
implementation of Erlang, edoc, and related tools have much better
support for parameterized modules than for using closures to emulate
parameterized modules.

We actually use the closure approach more often, because closures also
have desirable properties with regard to module reloading. Our use of
parameterized modules is almost entirely limited to mochiweb_request.
However, when we do use closures to capture state and provide a
module's worth of features it is not elegant due to boilerplate code
and Erlang syntax "features".


More information about the erlang-questions mailing list