Related articles |
---|
[11 earlier articles] |
Re: Defining polymorphism vs. overloading pase@orville.nas.nasa.gov (Douglas M. Pase) (1990-09-06) |
Re: Defining polymorphism vs. overloading ok@goanna.cs.rmit.OZ.AU (1990-09-07) |
Re: Defining polymorphism vs. overloading pardo@cs.washington.edu (1990-09-07) |
Re: Defining polymorphism vs. overloading pardo@cs.washington.edu (1990-09-07) |
Re: Defining polymorphism vs. overloading mmengel@cuuxb.ATT.COM (1990-09-11) |
Re: Defining polymorphism vs. overloading freek@fwi.uva.nl (1990-09-10) |
Re: Defining polymorphism vs. overloading pcg@cs.aber.ac.uk (Piercarlo Grandi) (1990-09-13) |
Re: Defining polymorphism vs. overloading voss@suna0.cs.uiuc.edu (1990-09-14) |
Re: Defining polymorphism vs. overloading stt@inmet.inmet.com (1990-09-15) |
Re: Defining polymorphism vs. overloading px@fctunl.rccn.pt (1990-09-20) |
Re: Defining polymorphism vs. overloading pcg@compsci.aberystwyth.ac.uk (Piercarlo Grandi) (1990-09-20) |
Re: Defining polymorphism vs. overloading chip@soi.com (Chip Morris) (1990-09-15) |
Newsgroups: | comp.compilers |
From: | Piercarlo Grandi <pcg@cs.aber.ac.uk> |
In-Reply-To: | pardo@cs.washington.edu's message of 7 Sep 90 16:52:16 GMT |
Keywords: | polymorphism |
Organization: | Coleg Prifysgol Cymru |
References: | <8133@amelia.nas.nasa.gov> <12977@june.cs.washington.edu> |
Date: | 13 Sep 90 12:16:23 GMT |
On 7 Sep 90 16:52:16 GMT, pardo@cs.washington.edu (David Keppel) said:
>[Ongoing discussion of overloading and polymorphism]
> To summarize:
> Given the name of of an operator where that operator applies to
> several types, the operator is
> * Polymorphic if all implementations are derived from a single
> specification.
> * Ad-hoc polymorphic or overloaded if the implementations are derived
> from several specifications.
> Oversimplified, but close?
Agreeably so, under current definitions. However the entire discussion
about *understanding* polymorphism and overloading (as well as defining
them), is seriously vitiated by one problem, that is always present:
why would we want to have overloading or polymorphism?
This is a less stupid question than it looks. The answer is *reuse*.
My usual mantra is worth repeating here:
What we really want is to be able to express notationally:
* reuse of interface
* reuse of semantics
* reuse of implementation
These are very different concepts. The various *mechanisms* that are
related (overloading, polymorphism, generic packages, private scopes,
inheritance, delegation, ...) do not directly address the support of
these concepts.
Just to go back to the mechanisms at hand, overloading is reuse of part
of an interface, and to a certain extent overloading of part of
semantics; when we have + overloaded for ints and floats the name is
reused, and so is part of the semantics, in that the mathematical
properties are assumed to be similar (hintsd of category theory). Things
start to look fishy when we overload + for string concatenation, as the
reuse of semantics thing starts to look very flimsy. Note that reuse of
interface is also partial here, because all these overloadings are
actually defined over two operands of the same type, even if the type is
different each time.
Polymorphism is reuse of implementation, with some hints of reuse of
semantics; for example you can use much the same logic to calculate the
length of a string and that of a file. Of course this relies on reuse of
semantics, because it will usually happen that the semantics of the
types over which we are polymorphic are somewhat similar. But, and this
rarely considered, it may happen that the same implementation (shape of
code) can be applied with entirely different results to different types;
this is especially obvious with functionals. Polymorphism also implies
some partial reuse of interface, as using the same implementation more
or less implies using the same interface.
What I would really like is for language designers to provide notation
to directly address the three distinct aspects of reuse, not with non
orthogonal and clumsy solutions.
--
Piercarlo "Peter" Grandi | ARPA: pcg%uk.ac.aber.cs@nsfnet-relay.ac.uk
Dept of CS, UCW Aberystwyth | UUCP: ...!mcsun!ukc!aber-cs!pcg
Penglais, Aberystwyth SY23 3BZ, UK | INET: pcg@cs.aber.ac.uk
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.