[erlang-questions] Parameterized module initialization

Andrew Berman rexxe98@REDACTED
Tue Jun 26 19:31:28 CEST 2012


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 <watson.timothy@REDACTED>wrote:

> I agree that something like functors would be a really nice abstraction
> for erlang.
>
> On 26 Jun 2012, at 17:18, Anthony Ramine <n.oxyde@REDACTED> 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
> > erlang-questions@REDACTED
> > http://erlang.org/mailman/listinfo/erlang-questions
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120626/304112f7/attachment.htm>


More information about the erlang-questions mailing list