[erlang-questions] Why do we need modules at all?

Richard O'Keefe ok@REDACTED
Wed May 25 06:38:57 CEST 2011


On 24/05/2011, at 8:39 PM, Dmitrii Dimandt wrote:

>> 
>> So I imagine:
>> 
>>    1) all functions have unique names
>>    2) there are no modules
>>    3) we discover the name of a function by searching metadata
>>       describing the function in a database
>>    4) all public functions (think open source) are in the same
>>       database
>> 
>> We could make a system to do this.
> 
> Hm... you'd still need *some* kind of modules.
> 
> For instance, in Webmachine each resource is expected to have some, or all, of predefined public/exported functions: to_html, resource_exists, allowed_methods etc.
> 
> So, each resource will have functions with the same name. If we move all functions to a global namespace, then how do we differentiate between these functions? Probably by naming them resource_name_function_name?


Meta-data.

   You say "I need a function about <topic1> with a ping cousin about <topic2>
            and a pong friend about <topic3>"
> 
> Furthermore, what do we do with behaviours? A behaviour is encapsulated within a module, also with a predefined set of exported funcions (and any number of custom exported functions).

In SML, a behaviour would be a functor.
In some other languages, it would be a single function
that took a record of anonymous functions &c and returned
a record of anonymous functions.  Inventing an ad hoc
syntax:

    local
       <{start ~ Start, stop ~ Stop, send ~ Send, explode ~ Explode}> =
           some¥wonderful¥new¥behaviour(<{
	       initial_state ~ 42,
               shut_down ~ fun (State) -> ... end,
               restart_policy ~ ad_infinitum,
               update_state ~ fun (State, Info) -> ... end
	    }>)
    in
	what you please using Start, Stop, Send, Explode
    end

The trick is to combine this with hot loading, and I have too many things
to do today to think of something.  That's what Joe is for...





More information about the erlang-questions mailing list