|Defining polymorphism vs. overloading firstname.lastname@example.org (1990-08-30)|
|Re: Defining polymorphism vs. overloading email@example.com (1990-09-01)|
|Re: Defining polymorphism vs. overloading firstname.lastname@example.org (1990-09-02)|
|Re: Defining polymorphism vs. overloading email@example.com (1990-09-03)|
|Re: Defining polymorphism vs. overloading firstname.lastname@example.org (1990-09-03)|
|Re: Defining polymorphism vs. overloading email@example.com (1990-09-03)|
|Re: Defining polymorphism vs. overloading firstname.lastname@example.org (1990-09-03)|
|[16 later articles]|
|From:||email@example.com (Oliver Sharp)|
|Date:||Thu, 30 Aug 90 21:19:43 -0700|
Once upon a time, shortly before an exam in a programming language course,
I asked myself "exactly what is the difference between these two things?"
The answer being "Ummm ... well ...", I decided to poke around. The
result is that things seem a bit murky. It seems as though:
o Overloading means using the same name (or symbol) to invoke different
code depending on the types of the arguments (or operands). So, an example
is +, which may do radically different things for integers, floats, and
complex numbers. In other words, you have different chunks of code
depending on the type. You may need to do some implicit casting, as in
promoting an integer to a complex number, before you can actually perform
o Polymorphism means using the same piece of code to operate on objects of
different types. In LISP, cons is polymorphic because you can give it
arguments of different types but it goes ahead and does its thing without
worrying about it.
Well, that seems pretty straight-forward so far, but in practice the
distinction isn't so clean. For example, think about square braces in C.
I've heard people say that they are overloaded, because they can apply to
arrays of different types ... but, by our just agreed on definitions, they
are really polymorphic. I'd look at someone funny if they said "braces are
polymorphic in C", though, wouldn't you? I've also heard people describe
things that are clearly overloaded as being polymorphic.
Having just taken a Linguistics class from Lakoff, I could explain all this
away with a lot of learned talk about radial categories, and prototypical
cases, and so forth ... but I'm really curious. What do YOU think the
distinction is? Or isn't there one? Do you use these terms consistently?
- Oliver Sharp
Return to the
Search the comp.compilers archives again.