Parameterised modules

Mikael Pettersson <>
Mon Sep 1 16:45:02 CEST 2003


Sean Hinde writes:
 > So you are proposing that new() should always have a single parameter 
 > which is a list of tagged tuples with magic properties? This would work 
 > I think, though it is getting away from the reason to provide the 
 > feature (Clearer code).
 > 
 > If this was taken further so that a call to foo:new() was a wrapper for 
 > foo:new([]) this would be quite clean. Maybe even then using a 
 > parameterised module without ever calling new() would give the default 
 > behaviour - thus removing the burden of additional understanding 
 > required before a module could be used at all. This is not as pretty as 
 > Richards version though..

All I'm proposing is to change from call-with-parameters-by-postion
to call-with-parameters-by-label. The first is commonplace but
can't handle default values for omitted parameters. The second is
bulkier to type (but not much) but handles omitted parameters easily;
it also has some precedence in record syntax and other languages
like SML (in SML, tuples are syntactic sugar for records with numeric
labels).

The callback example isn't the one that motivates me. I'm a diehard
SML fan, and I love the way SML lets me structure code and create
multiple specialised instances of generic modules.

(I personally don't care for default parameters to modules. I only
proposed it because you seemed to want a way to either supply a
given parameter or not -- with the module taking appropriate action.)

/Mikael



More information about the erlang-questions mailing list