|[17 earlier articles]|
|Re: Polymorphism vs. Overloading email@example.com (1994-10-31)|
|Re: Polymorphism vs. Overloading firstname.lastname@example.org (1994-10-26)|
|Re: Polymorphism vs. Overloading email@example.com (1994-10-31)|
|Re: Polymorphism vs. Overloading firstname.lastname@example.org (1994-10-31)|
|Re: Polymorphism vs. Overloading email@example.com (Martin Odersky) (1994-10-31)|
|Re: Polymorphism vs. Overloading firstname.lastname@example.org (1994-10-27)|
|Re: Polymorphism vs. Overloading email@example.com (1994-10-28)|
|Re: Polymorphism vs. Overloading firstname.lastname@example.org (1994-10-28)|
|Re: Polymorphism vs. Overloading email@example.com (1994-10-29)|
|Re: Polymorphism vs. Overloading firstname.lastname@example.org (1994-10-29)|
|Re: Polymorphism vs. Overloading email@example.com (1994-11-01)|
|Re: Polymorphism vs. Overloading firstname.lastname@example.org (kanze) (1994-11-01)|
|Re: Polymorphism vs. Overloading davidm@Rational.COM (1994-10-31)|
|[7 later articles]|
|From:||email@example.com (Pete Jinks)|
|Organization:||Dept of Computer Science, University of Manchester, U.K.|
|Date:||Fri, 28 Oct 1994 16:22:32 GMT|
Gabriela O. de Vivo <firstname.lastname@example.org> wrote:
>the exact difference between Polymorphism and Overloading.
This was discussed about a year ago, if you can find the back issues.
Joseph H Allen <email@example.com> wrote:
>The difference is purely syntactical.
and then showed how this was so in OO languages (I think). I think the
conclusion in the previous discussion was similar, but I didn't pay much
attention at the time.
There is maybe a dichotomy, though:
some polymorphic/overloaded operations are so because they do not
need to know the exact type they are working on e.g. higher-order functions,
list-mangling etc. in functional languages - CAR and CDR can work on lists
with any type of elements if all we want to do is e.g. reverse the list, or
count the elements, or apply a given operation to each list element. An
imperative approximation to this is e.g. qsort in C, but the user has to be
really careful to supply the correct comparison operation.
some polymorphic/overloaded operations are so because they hide
multiple implementations, one for each type they can deal with e.g. +, which
can be on ints, reals, sets, etc.. In this case, at some point, the compiler
or run-time system has to decide which implementation to use. OO languages
make a point of doing this via runtime binding for maximum flexibility (but
I don't want to make a big deal about this difference as:
the former only works because we have limited the kind of data type
that we are willing to work with (e.g. to lists/arrays of pointers), although
maybe we never want to write more generally polymorphic routines in practice?
they both involve the user or the system making some decision as to
how to implement the polymorphic operation in each instance - this is
particularly obvious with qsort.
SML (a functional language) calls the first polymorphism and the second
overloading. As Joseph Allen wrote, OO languages seem to refer to the second
as polymorphism when it applies to user-defined operations and overloading
when it applies to built-in operations (and maybe ignore the first, as it is
not much of an option in most imperative & OO langauges).
It would be nice to know if this is right, as it is the sort of thing I have
to lecture about soon!
Return to the
Search the comp.compilers archives again.