Re: Polymorphism vs. Overloading

norman@flaubert.bellcore.com (Norman Ramsey)
Mon, 24 Oct 1994 01:47:16 GMT

          From comp.compilers

Related articles
Polymorphism vs. overloading johnson@cs.uiuc.edu (Ralph Johnson) (1990-09-09)
Re: Polymorphism vs. overloading norman@a.cs.okstate.edu (1990-09-12)
Re: Polymorphism vs. overloading sakkinen@jyu.fi (1990-09-14)
Polymorphism vs. Overloading gdevivo@conicit.ve (1994-10-22)
Re: Polymorphism vs. Overloading jhallen@world.std.com (1994-10-22)
Polymorphism vs. Overloading nandu@cs.clemson.edu (1994-10-27)
Re: Polymorphism vs. Overloading norman@flaubert.bellcore.com (1994-10-24)
Re: Polymorphism vs. Overloading ichudov@wiltel.com (1994-10-28)
Re: Polymorphism vs. Overloading strohm@mksol.dseg.ti.com (1994-10-28)
Re: Polymorphism vs. Overloading ryer@dsd.camb.inmet.com (1994-10-28)
Re: Polymorphism vs. Overloading mac@coos.dartmouth.edu (1994-10-25)
Re: Polymorphism vs. Overloading joe@sanskrit.ho.att.com (1994-10-31)
Re: Polymorphism vs. Overloading geld@cs.sun.ac.za (1994-10-31)
[24 later articles]
| List of all articles for this month |

Newsgroups: comp.compilers
From: norman@flaubert.bellcore.com (Norman Ramsey)
Summary: polymorphism == property of function; overloading == notation
Keywords: polymorphism
Organization: Bellcore, Morristown NJ
References: 94-10-144
Date: Mon, 24 Oct 1994 01:47:16 GMT

A polymorphic function accepts arguments of different types, but has
the same semantics (and usually implementation) regardless of the
types of the arguments. The the standard ML function 'null' may be
applied to lists of any type (list of integer, list of string, ...),
but it always has the same meaning and implementation. I believe this
style of polymorphism is called 'parametric polymorphism', perhaps
because it is the function parameter that can have different types.


Overloading is a notational device that permits a programmer to use
the same notation to mean one of several different things (i.e.,
different semantics and implementation) depending on the types of
arguments (and possibly also results). For example, in Ada it is
possible to define an overloaded function One (I *will* get the
notation wrong; I haven't looked at Ada for years):


    procedure One() returns integer;
    procedure One() returns float;
    procedure One() returns matrix;


Note that this is three different functions, but applying any of the
functions use the same notation:


    One()


which could mean an integer, a floating-point number, or an identity
matrix depending on the context (As determined by Ada's visibility and
overloading rules).




If you think of polymorphism as a property of a function and
overloading as a notational trick, you won't be far wrong.


Norman Ramsey
--


Post a followup to this message

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