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

Simon Peyton-Jones simonpj at microsoft.com
Fri Feb 27 09:28:11 EST 2004

> 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

Remember, too, that in OO languages the type of 'fm' is usually
declared, in advance, by the programmer.  In Haskell it isn't.   That
makes it much harder to figure out which 'add' function is going to be

Which 'add' function is chosen depends on type type of 'fm'.  But the
add function that is chosen in turn influences the type of the other
arguments.  For example, in the call (fm.add foo), the type of 'foo' is
influenced by the choice of 'add'.  But the type of 'foo' might (by the
magic of type inference) affect the type of 'fm'....

In Haskell today, you can at least tell what value is bound to each
identifier in the program, *without* first doing type checking.  And the
binding story, all by itself, is somewhat complicated.  The typing story
is also (very) complicated.  Winding the two into a single indissoluble
whole would make it far more complicated still.

My nose tells me that this way lies madness.  

But I've been wrong before.


More information about the Haskell mailing list