At 9:36 am +0100 19/5/99, D. Tweed 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.

etc.

Hope+C supported overloading about 10 or so years ago (and still does in its latest 
incarnation as the Concurrent Massey Hope+C). You can overload (i.e. use the same 
identifier for) functions, constructors, types, etc. (but not module names!). Both 
argument and return types are used to resolve overloading. Though Hope+C has type 
declarations for top-level functions the type-checker actually supports inference and 
in the "new" syntax for function declarations uses it - so Hope+C provides 
polymorphism, existential types, type inference and overloading resolution. (The type 
system was also designed with supporting a Haskell class-like notion pre-Haskell 
classes, but this was never done as it would have required changes to the language 
syntax that were not possible under the project at the time [existential types got in 
as they required no syntax changes]). What's the problem? ;-)

Under the "old" function syntax in Hope+C you got weird "benefits" from overloading. 
E.g.:

        dec f : int -> int;
        dec f : char -> char;

        --- f(1) <= 2;  ! equation for f: int -> int
        --- f('a') <= b;        ! equation for f: char -> char
        --- f(x) <= x;  ! equation for both...

Allowing full ad-hoc overloading can lead to ambiguity problems, e.g:

        let f : int -> real == ....
        let f : int -> char == ...

        let g : real -> bool == ...
        let g: char -> bool == ...

        .... if g(f x) .... <- ambiguous

However the compiler can easily spot these an issue an "ambiguous overloading" error 
at the right point. Hope+C actually has a feature for "best fit overloading" which 
allows a function with specific types to be picked in preferecne to one with variable 
type (e.g. consider isSame : alpha # alpha -> bool & isSame : int # int -> bool), but 
it has limited applicability.

Papers on the type system have been published some years ago (the type system itself 
was part of my PhD in the distant past! :-)) and are available via the web site below 
if people are interested.

So to answer the question: it can be done, by a simple existance proof :-)

Cheers,
        Nigel
--
Dr Nigel Perry                  Email: [EMAIL PROTECTED]
IIS&T                           Tel:   +64 6 350 4007
Massey University               Fax:   +64 6 350 2259
Palmerston North                Ftp/Gopher/WWW: smis-asterix.massey.ac.nz
New Zealand                     (Mac software/Research papers/PAL group)

It makes as much sense to wear a "cycle" style helmet in a car as on a bike...
Choosing to wear one on a bike but not in a car is mere inconsistency.
Refusing to wear one in a car while insisting others do so on a bike is pure hypocrisy.
Guess which the Government is... :-(
        Politics and hypocrisy before safety - the NZ Helmet Law, NZ's Shame


Reply via email to