[erlang-questions] Parameterized module initialization
Fred Hebert
mononcqc@REDACTED
Tue Jun 26 21:09:00 CEST 2012
The problem I have with all of these things is that parametrized modules
will automatically mess up with the arities of function when they're
perceived and used. This means most tracing is going to be wrong.
I can't trace on {PMod, Fun, Arity} where PMod is a parametrized module,
because the current underlying representation ({Mod, Data}) isn't
accepted by tools such as dbg.
I can't trace on {Mod, Fun, Arity} where Mod is the actual module I
think I use, because the Arity is expanded by PMods to pass hidden
arguments.
What I actually need to do is {Mod, Fun, Arity+1} while knowing what I
have is a parametrized module. Messing with arity is not something I'm a
fan of. I'm also not sure what impact we have when using PMods and the
fun M:F/A expression, but I can already say it isn't obvious if I should
expect it to break or not.
They can be an abstraction, but at best they're a leaky one that can be
rather confusing when using well known and supported tools.
I have no solution to offer, though.
On 12-06-26 2:32 PM, Richard Carlsson wrote:
>
> Parameterized modules in Erlang already correspond to what ML/Caml
> calls "functors": an abstraction over modules. What you decide to
> parameterize over: terms or other modules (or possibly even types,
> though I'm not sure what would be needed to support that), is up to you.
>
>> You would have a string functor which takes as a parameter a string
>> implementation module, either ansi_string or utf8_string. You could
>> then abstract the common stuff from ansi_ and utf8_ in string.
>
> And that is just as straightforward to do in Erlang as in Caml:
>
> -module(string, [StringImpl]).
> -export([reverse/1]).
> reverse(S) -> StringImpl:reverse(S)
>
> and then you should probably hide the details of instantiating such a
> module behind some factory module or facade:
>
> -module(string_maker).
> -export([...]).
> ansi_string_module() -> string:new(ansi_string).
> utf8_string_module() -> string:new(utf8_string).
>
>
> /Richard
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
More information about the erlang-questions
mailing list