Defining polymorphism vs. overloading

oliver@karakorum.berkeley.edu (Oliver Sharp)
Thu, 30 Aug 90 21:19:43 -0700

          From comp.compilers

Related articles
Defining polymorphism vs. overloading oliver@karakorum.berkeley.edu (1990-08-30)
Re: Defining polymorphism vs. overloading burley@world.std.com (1990-09-01)
Re: Defining polymorphism vs. overloading wright@gefion.rice.edu (1990-09-02)
Re: Defining polymorphism vs. overloading compilers-sender@esegue.segue.boston.ma.us (1990-09-03)
Re: Defining polymorphism vs. overloading hrubin@l.cc.purdue.edu (1990-09-03)
Re: Defining polymorphism vs. overloading px@fctunl.rccn.pt (1990-09-03)
Re: Defining polymorphism vs. overloading plph@caen.engin.umich.edu (1990-09-03)
[16 later articles]
| List of all articles for this month |

Newsgroups: comp.compilers
From: oliver@karakorum.berkeley.edu (Oliver Sharp)
Keywords: design
Organization: Compilers Central
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
        the operation.


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


Post a followup to this message

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