"S.D.Mechveliani" wrote:
> 
> To
> 
> >> I am writing code that would like to use the word "product" as a field
> >> selector for a Product (object representing something for sale).
> >> Unfortunately, it can't easily use "product" because the prelude claims
> >> the word for multiplication.
> 
> Johannes Waldmann  [EMAIL PROTECTED]   writes
> 
> > seems like another reason to advocate ad hoc polymorphism
> > (allow a name to denote several things, as long as they have
> > different types).
> ...
> 
> I join this suggestion.
> Though   import Prelude hiding(product)
> 
> may solve this problem with `product',  ad hoc polymorphism is still
> very desirable.
> As they are the overlapping instances with ad hoc resolution - more
> generic than allowed by recent Haskell compilers.

When considering changes to a language, I think one needs to carefully
measure the difference between convenience and necessity/correctness. I
think everyone will agree that ad hoc polymorphism (aka overloading) is
very _convenient_ but I don't think that everyone will agree that it is
the _correct_ thing to do. I know a few OO purists who will insist that
overloading is a Bad Thing. Their reasoning: If a function does similar
things, but with different types, define the function in terms of a
common base class. If two functions do radically different things, but
happen to be named the same, you have a naming problem. One of the
functions should change its name.

There are some weaknesses in this rationale. One is the existence of
homonyms in natural languages. For instance, the word "product" is a
perfectly good name for two functions that do very different things.

Perhaps a "better" solution than ad hoc polymorphism would be to provide
a more convenient namespace syntax. Am I mistaken in thinking that
overloading, for overloading's sake, isn't what is wanted; what is
wanted is to be able to easily differentiate between two functions that
happen to be named the same? Ad hoc polymorphism is probably the most
"convenient" differentiation mechanism, but is it the "best"?

Mind you, I don't have any brilliant solutions. I just thought that I
might clarify(?) the problem a bit.

- Michael Hobbs


Reply via email to