On 20-May-1999, Nigel Perry <[EMAIL PROTECTED]> wrote:
> > On Wed, 19 May 1999, Kevin Atkinson wrote:
> > 
> > > I was wondering what the generally felling to allowing true ad-hoc
> > > overloading like it is done in C++ in Java but more powerful because
> > > functions can also be overloaded by the return value.
> 
> Hope+C supported overloading about 10 or so years ago (and still does
> in its latest incarnation as the Concurrent Massey Hope+C).

Mercury is another language that supports ad-hoc overloading.
Mercury also supports Haskell-style type classes.

...
> Hope+C provides
> polymorphism, existential types, type inference and overloading
> resolution.

Mercury doesn't yet officially support existential types
(the current implementation does in fact have some support for them,
but it is not yet documented -- we hope to support them properly in
a future release).  But Mercury does support polymorphism, type
inference, and overloading resolution.

> Allowing full ad-hoc overloading can lead to ambiguity problems, e.g:
...
> However the compiler can easily spot these an issue an "ambiguous
> overloading" error at the right point.

Yes, and then the programmer can easily insert an explicit qualifier
to resolve the ambiguity.

Haskell reports an error when you declare two functions or
two constants with the same name.  Mercury reports an error only when
you _use_ an overloaded name, and only if the use is ambiguous.
The result is that in Haskell you often need to embed qualifiers
in the names of constants or functions, e.g. instead of writing

        data MovementType = Run | Walk | Skip | Hop | Fly
        data FileAction = Copy | Delete | Run

you write something like

        data MovementType = MovementTypeRun | MovementTypeWalk
                          | MovementTypeSkip | MovementTypeHop
                          | MovementTypeFly
        data FileAction = FileCopy | FileDelete | FileRun

In Mercury you can use the more consise data declaration and qualify
it only when it is actually used in an occurrence which is ambiguous.
For most uses, the compiler can figure out from the context which
one you mean.  Thus in Haskell you often need to use more qualifiers
than in Mercury.

-- 
Fergus Henderson <[EMAIL PROTECTED]>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger [EMAIL PROTECTED]        |     -- the last words of T. S. Garp.


Reply via email to