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