Parameterised modules

Chris Pressey <>
Thu Sep 4 19:34:50 CEST 2003


On 04 Sep 2003 11:37:08 +0200
"Lon Willett" <> wrote:

> And while on the topic of parameterised modules, an issue that I am
> concerned with is the handling of code change.  I am not convinced
> that the proposed handling is correct.  I am not even sure what the
> _right_thing_ is.

As someone who didn't see the talk, forgive me if this is way off base.
But I think I prefer a different approach.  Although I forget exactly
who mentioned it, I think it was one of the gurus who occasionally
posts, during the last round of wish lists.

Instead of parameterized modules, what about full-fledged lambda
modules?

Analogous to funs, I'll call them mods.  Also analogous to funs I'll use
the following syntax:

  Mod = mod
    function1(A1, A2) -> something.
    function2(A1, A2) -> something_else.
  end,

This way you can 'parameterize' a module like so:

  String = "Hello, world!",
  Mod = mod
    print() -> io:fwrite("~s", [String]).
  end,
  Mod:print().

or, a better example might be

  printing_module(String) ->
    mod
      print() -> io:fwrite("~s", [String]).
    end.

  whatever() ->
    printing_module("Hello, world!"):print().

The thing is that these wouldn't be subject to code change (just like
funs aren't.)  Also, they might be able to be stored whole cloth in
mnesia tables etc (again just like funs.)  While these properties
wouldn't make them suitable for everything (just like funs aren't,) I
think they would be perfect for certain things (just like funs are.)

They also strike me as much simpler than parameterized modules (from the
programmer's point of view; I'm not really deeply considering how they'd
have to be implemented.)

Thoughts?

-Chris



More information about the erlang-questions mailing list