[erlang-questions] Hungarian notation for Erlang / ETL
David Holz
david_holz@REDACTED
Wed Jan 9 23:24:06 CET 2008
[I really wish reply-to was set to erlang-questions@REDACTED, or maybe hotmail is just stupid. Yet again, I accidentally first replied to the sender instead of the list.]
From: exta7@REDACTED
> 2. I wasn't talking about implementing object using Erlang processes. I
> talking about much simpler and functional solution, like providing
> behaviour, like:
>
> -module(collection).
> -export([behaviour_info/1]).
>
> -module(queue).
> -behaviour(collection).
>
> %% ...
>
> -module(set).
> -behaviour(collection).
>
> %% ...
>
> -module(stack).
> -behaviour(collection).
The shortcoming of that is that there is no dispatch to the correct module for that datatype. You can't just do length(Data), you'd have to explicitly know to call queue:length(Data) or set:length(Data), etc. You can't just pass around a data object because that doesn't indicate which module's functions to use on it. I could see a similar packaging to records being used:
Queue module returns {queue, [Data]}, stack module returns {stack, [Data]}, etc
and in the collection module it simply dispatches to whatever module is named in the first field:
collection:length(A = {Module, _}) -> Module:length(A) end.
collection:to_string(A = {Module, _}) -> Module:to_string(A) end.
etc
Of course, this is exactly what OO implementations do, having a vtable or type identifier embedded in each object to tell what class's methods to call when using the object.
_________________________________________________________________
Put your friends on the big screen with Windows Vista® + Windows Live™.
http://www.microsoft.com/windows/shop/specialoffers.mspx?ocid=TXT_TAGLM_CPC_MediaCtr_bigscreen_012008
More information about the erlang-questions
mailing list