[erlang-questions] Parameterized module initialization

Andrew Berman <>
Tue Jun 26 19:33:46 CEST 2012


I'd also like to know why there are "hidden" features of Erlang in the
first place.  I don't understand why they cannot be documented and accepted
in the community and if not, just get rid of them.  No one wants to use
something that might possibly be removed in the future or unsupported.
 Just put it in the language or get rid of it.

--Andrew

On Tue, Jun 26, 2012 at 10:31 AM, Andrew Berman <> wrote:

> I agree too, that would be really nice to get something like that in
> Erlang.
>
>
> On Tue, Jun 26, 2012 at 10:26 AM, Tim Watson <>wrote:
>
>> I agree that something like functors would be a really nice abstraction
>> for erlang.
>>
>> On 26 Jun 2012, at 17:18, Anthony Ramine <> wrote:
>>
>> > Le 26 juin 2012 à 16:56, Joe Armstrong a écrit :
>> >
>> >> I like this mechanism.  This way of hiding additional data is very
>> flexible.
>> >>
>> >> I've used this in several programs, and the resulting code is easy to
>> >> understand. This nice thing is that using this you can make very nice
>> >> client APIs. For example, for string processing you might say
>> >>
>> >>            Str = {ansi_string, "abc"},         or
>> >>            Str = {utf8_string, "u+1234"}
>> >>
>> >> And then when you call
>> >>
>> >>            Str:substr(1,4)
>> >>
>> >> Get the correct behaviour depending upon the underlying string type ie
>> >> either ansi_string:substr(1,4,{ansi_string,"abc"}) or
>> >> utf8_sting:substr(1,4,{utf8_string, "u+1234"} ) will be called
>> >>
>> >> If you write a program where strings might be in latin1, or utf8 or
>> >> something else you'd still
>> >> have to tag the string (as in say {latin1, "abc"}) so you knew what
>> >> the encoding was and still
>> >> have to call different modules depending upon the tag. This is what
>> >> the above mechanism does
>> >> so it's very nice for hiding the mess in polymorphic interfaces.
>> >>
>> >> /Joe
>> >
>> > I think it is quite ugly to have terms as module parameters; a more
>> beautiful way in my opinion would be to have something like Caml functors,
>> which are mappings from structures (modules in Erlang) to structures.
>> >
>> > 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.
>> >
>> > Regards,
>> >
>> > --
>> > Anthony Ramine
>> > _______________________________________________
>> > erlang-questions mailing list
>> > 
>> > http://erlang.org/mailman/listinfo/erlang-questions
>> _______________________________________________
>> erlang-questions mailing list
>> 
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120626/6d3337e9/attachment.html>


More information about the erlang-questions mailing list