[Haskell] Per-type function namespaces (was: Data.Set whishes)

Gabriel Dos Reis gdr at integrable-solutions.net
Fri Feb 27 01:20:30 EST 2004

"David Bergman" <davidb at home.se> writes:

| > The idea that I've been throwing around is to be able to define a 
| > separate namespace for each type; a function can either belong in a 
| > "global" (default) namespace, or belong in a particular type's 
| > namespace.  So, in the above example, instead of writing "addToFM fm 
| > ...", we could instead associate an 'add' function with the FiniteMap 
| > type, so we could write "fm.add ..." instead.  Provided that fm's type 
| > is monomorphic, it should be possible to call the 'correct' add 
| > function; if we defined another 'add' function that's associated with 
| > the Set type, that will only get called if the 'x' in "x.add" is of 
| > type :: Set.  So, like OO languages which inherently give separate 
| > namespaces to their different objects, here we give separate 
| > namespaces to different
| > (monomorphic) types.  In this case, if one simply writes "add" instead 
| > of "x.add", the compiler throws an error, because there is no 'add' 
| > function defined in the default namespace; add is only defined when a 
| > programmer writes "x.add" where x :: FiniteMap or x ::
| > Set[1].
| This overloading by namespace is usually called either ADL
| (Argument-Dependent Lookup) or Koenig Lookup (especially in C++.)

Actually in C++, it is called "argument dependent name lookup", and
that is the way the C++ definition text calls it. As Andy Koenig has
himself pointed out, he did not invent that rule.  He mentionned it
when the C++ committee was solving a name look-up problem
posed by namespaces to operator functions.  That name look-up rule
was later generalized to non-operator to cover the function-call
syntax -- which is what is most known today and referred to above. 

This ends my C++ hour on Haskell list :-)

-- Gaby

More information about the Haskell mailing list