Re: Polymorphism vs. Overloading

Martin Odersky <odersky@ira.uka.de>
Mon, 31 Oct 1994 22:29:27 GMT

          From comp.compilers

Related articles
[15 earlier articles]
Re: Polymorphism vs. Overloading Mike.Chapman@muc.de (Mike Chapman) (1994-10-31)
Re: Polymorphism vs. Overloading jsm@id.dth.dk (1994-10-31)
Re: Polymorphism vs. Overloading sofkam@rpi.edu (1994-10-31)
Re: Polymorphism vs. Overloading andand@csd.uu.se (1994-10-26)
Re: Polymorphism vs. Overloading dekker@dutiag.twi.tudelft.nl (1994-10-31)
Re: Polymorphism vs. Overloading danhicks@aol.com (1994-10-31)
Re: Polymorphism vs. Overloading odersky@ira.uka.de (Martin Odersky) (1994-10-31)
Re: Polymorphism vs. Overloading bevan@cs.man.ac.uk (1994-10-27)
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)
[9 later articles]
| List of all articles for this month |
Newsgroups: comp.compilers
From: Martin Odersky <odersky@ira.uka.de>
Keywords: polymorphism
Organization: Compilers Central
References: 94-10-144
Date: Mon, 31 Oct 1994 22:29:27 GMT

Gabriela O. de Vivo writes:


> At some point a question raised about the exact difference between
> Polymorphism and Overloading.


There are today three predominant kinds of polymorphism in programming
languages:


parametric sometimes called generics, or (as in C++) templates
subtyping sometimes (mistakenly) called inheritance
ad-hoc sometimes called overloading


The difference between overloading and the other two kinds of
polymorphism is that when a function is overloaded, there exists
different source code for each possible combination of argument
types. By contrast, in parametric polymorphism there is just one
source body which gets instantiated by type arguments. The same holds
for subtyping: A function F that can take arguments of type T can take
arguments of any subtype of T, without having to change the code of F.


An important difference between parametric polymorphism and subtyping
polymorphism is that only parametric polymorphism can express coupling
of argument types. I.e. it is impossible to express precisely the type


forall a: (a, a) -> a


in a pure subtyping regime. The best one could do would be


(Any, Any) -> Any


but that would loose the coupling between the two argument types and
between the argument and result types.


=========================================================================


Prof. Martin Odersky odersky@ira.uka.de
Department of Computer Science Tel. +49 (0721) 608 3495
University of Karlsruhe Fax +49 (0721) 69 40 92
76128 Karlsruhe, Germany
--


Post a followup to this message

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