Re: Polymorphism vs. Overloading

davidm@Rational.COM (David Moore)
Mon, 31 Oct 1994 21:54:55 GMT

          From comp.compilers

Related articles
[23 earlier articles]
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)
Re: Polymorphism vs. Overloading bill@amber.ssd.csd.harris.com (1994-11-01)
Re: Polymorphism vs. Overloading drichter@pygmy.owlnet.rice.edu (1994-11-01)
Re: Polymorphism vs. Overloading bevan@cs.man.ac.uk (1994-11-02)
Re: Polymorphism vs. Overloading bimbart@CS.kuleuven.ac.be (Bart Demoen) (1994-11-02)
Re: Polymorphism vs. Overloading monnier@di.epfl.ch (1994-11-01)
Re: Polymorphism vs. Overloading nickb@harlequin.co.uk (1994-11-09)
[1 later articles]
| List of all articles for this month |

Newsgroups: comp.compilers
From: davidm@Rational.COM (David Moore)
Keywords: polymorphism
Organization: Rational Software Corporation
References: 94-10-144 94-10-180
Date: Mon, 31 Oct 1994 21:54:55 GMT

ryer@dsd.camb.inmet.com (Mike Ryer) writes:


>Overloading happens at compilation time -- the compiler decides which function
>to invoke based on statically-determined types of the operands.


>Polymorphism may not happen until runtime -- the compiler generates code that
>fans out based on the runtime value of a tag.


This is the answer I would have given too - until the question was
asked by someone who almost certainly already knew this answer.


If you instead try to define the difference in terms of the semantics
of the language instead of how the language is implemented, it is
somewhat harder.


My suggestion would be that polymorphic functions impose more structure
than overloaded functions.


Let's just consider the case of functions with the same parameter (and result)
profiles - this is the interesting case.


For polymorphic functions, there is a semi-lattice on the functions induced
by the semi-lattice on the types. This semi-lattice is just the derivation
tree - if type t2 is derived (directly or indirectly) from type t1 then
t1<t2. If we have function f:t1 and a function f:t2, we can say
f:t1<f:t2.


One can probably extend this to multiple parameters, although many
languages only support polymorphism in one parameter.


For overloaded functions, no such order exists.


Quite clearly, in a language like C++, a given identifier can be
both overloaded and polymorphic, because two types need not be in a
common semi-lattice, so there can be some polymorphic definitions and
some overloaded definitions for an identifier.


However, if we accept this definition, then in a language where all types
are derived from some basic type (Smalltalk?) there is no such thing
as overloading (of functions with the same profiles) - only polymorphism.




--


Post a followup to this message

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