[Prev][Next][Index][Thread]

OO polymorphism



Hello.

I was having a minor terminological squabble with someone, and since we
reached no solution, I thought to ask the experts.

Here's the issue. In the object-oriented culture, "polymorphism"
typically means dynamic dispatching: methods in subclasses can operate
differently from methods in superclasses. The question is: where does
this sort of behavior fit in the Cardelli/Wegner taxonomy of different
kinds of polymorphism [CW85]?

My view is that this is a special, systematic form of ad
hoc-polymorphism: an operation can have multiple differing
implementations, one of which is chosen depending on the type of the
function's argument. Although in OO languages this dispatching is
dynamic and based on an object's runtime _class_, and a strict
interpretation of "type" limits the concept of polymorphism to a purely
static context, nevertheless in Benjamin Pierce's types book [Pie02, p.
340] the statically untyped multimethods of CLOS are counted as ad
hoc-polymorphism. To my mind single-dispatch OO is essentially a limited
version of the same.

My opponent contends that what is found in the methods of eg. C++ and
Java is, in fact, inclusion polymorphism: an argument of a subtype can
be used wherever an argument of a supertype can. Both the
Cardelli/Wegner paper and Pierce's book seem to imply the same. However,
in the original paper it is said of inclusion polymorphism [CW85, p.
478]:

	Similarly, operations are careful to interpret the
	representations uniformly so that they can work uniformly on
	elements of subtypes and supertypes.

Dynamic dispatch doesn't seem to me to be "uniform" to me, although of
course at the implementation level there usually is a "uniform"
operation of looking up the implementation from a vtable and jumping to
that. So I'd limit pure inclusion polymorphism to such things as union
types, record types and non-virtual methods: the "same thing" is done to
all arguments regardless of their exact type (or class).

Can someone offer advice on which is the preferable interpretation? I'll
gladly accept "they both are, silly" for an answer. I'm just interested
in hearing if there's an established consensus on this.

Thanks for any feedback.


Lauri Alanko
la@iki.fi

[CW85]	Cardelli, Luca and Peter Wegner. On understanding types, data
	abstraction, and polymorphism. Computing Surveys, 17(4):471-522,
	December 1985.

[Pie02] Pierce, Benjamin. Types and Programming Languages. MIT Press,
	2002.