[Haskell-cafe] Re: Overloading functions based on arguments?

John A. De Goes john at n-brain.net
Sat Feb 14 09:56:59 EST 2009

On Feb 13, 2009, at 6:31 PM, Krzysztof Skrzętnicki wrote:
> On Fri, Feb 13, 2009 at 22:37, John A. De Goes <john at n-brain.net>  
> wrote:
>> On Feb 13, 2009, at 2:11 PM, Jonathan Cast wrote:
>>> The compiler should fail when you tell it two mutually contradictory
>>> things, and only when you tell it two mutually contradictory things.
>> By definition, it's not a contradiction when the symbol is  
>> unambiguously
>> typeable. Do you think math textbooks are filled with  
>> contradictions when
>> they give '+' a different meaning for vectors than matrices or real
>> numbers???
> I can easily imagine a book which uses some operator in ambiguous way
> yet relies on readers' intelligence in solving that issue. It is OK to
> do that as long as it is easy. However: it can get arbitrarily worse.

Don't overlook the advantages of using familiar operators and names:  
you have some intuition about '+' and 'map', so if you see them, then  
you'll have some idea what they do (assuming the author is neither  
stupid nor malicious). However, if you see some operator like '$>+' or  
some name like 'pp3', then you probably won't have any intuition about  

Writing good software is about conveying intentions, and part of the  
way we can do that is relying on what other people already know. Which  
means using familiar names and operators when it is helpful to do so.

> I would
> consider any book which is hard
> to read because of that badly written. Things are quite similar with  
> the code.

I consider the current state of affairs quite poor: namely, abuse of  
type classes and alternate names and operators that aren't very  
suggestive, but were chosen purely to avoid conflicts.

> Programming language should be easy to reason about for both computers
> and humans. Compiler should therefore disallow programming style  
> that is
> inaccessible for potential readers. Want to overload something? Well,
> use typeclasses to be explicit about it.

Type classes were not designed for name overloading. They're designed  
to factor out common patterns in programming. You shouldn't use a type  
class just because you want to use a name or operator.

And as I said before, if you want to "disallow programming style that  
is inaccessible for potential readers," then you should disallow the  
current state of affairs.


John A. De Goes
The Evolution of Collaboration

http://www.n-brain.net    |    877-376-2724 x 101

More information about the Haskell-Cafe mailing list