Re: Polymorphism vs. Overloading

pjj@cs.man.ac.uk (Pete Jinks)
Fri, 28 Oct 1994 16:22:32 GMT

          From comp.compilers

Related articles
[17 earlier articles]
Re: Polymorphism vs. Overloading sofkam@rpi.edu (1994-10-31)
Re: Polymorphism vs. Overloading andand@csd.uu.se (1994-10-26)
Re: Polymorphism vs. Overloading dekker@dutiag.twi.tudelft.nl (1994-10-31)
Re: Polymorphism vs. Overloading danhicks@aol.com (1994-10-31)
Re: Polymorphism vs. Overloading odersky@ira.uka.de (Martin Odersky) (1994-10-31)
Re: Polymorphism vs. Overloading bevan@cs.man.ac.uk (1994-10-27)
Re: Polymorphism vs. Overloading pjj@cs.man.ac.uk (1994-10-28)
Re: Polymorphism vs. Overloading jhf@c3serve.c3.lanl.gov (1994-10-28)
Re: Polymorphism vs. Overloading mmcg@bruce.cs.monash.edu.au (1994-10-29)
Re: Polymorphism vs. Overloading hbaker@netcom.com (1994-10-29)
Re: Polymorphism vs. Overloading jhallen@world.std.com (1994-11-01)
Re: Polymorphism vs. Overloading kanze@lts.sel.alcatel.de (kanze) (1994-11-01)
Re: Polymorphism vs. Overloading davidm@Rational.COM (1994-10-31)
[7 later articles]
| List of all articles for this month |

Newsgroups: comp.compilers
From: pjj@cs.man.ac.uk (Pete Jinks)
Keywords: polymorphism
Organization: Dept of Computer Science, University of Manchester, U.K.
References: 94-10-144 94-10-154
Date: Fri, 28 Oct 1994 16:22:32 GMT

Gabriela O. de Vivo <gdevivo@conicit.ve> 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 <jhallen@world.std.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
minimal checking?).


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!
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.