2010-04-30

polymorphic vs evolutionary subtyping

4.23: adda/oop/polymorphic vs evolutionary subtyping:

. the crux of subtyping is being
compatable with multiple types;
structural subtyping is allowing compatability between
any interfaces that share operations having
the same name and parameters;
nominal subtyping is where compatability is declared:
a subtype is compatible with its supertype
because it defined itself as supporting that supertype .
. the 2 types of nominal subtyping
are tentatively named here:
polymorphic subtyping, and
evolutionary subtyping .
. the term polymorphic refers to a single genome
that results in individuals of varying form;
eg, drones, queen, workers .
. evolution is about extending the capabilities
that were inherited .
. when considering the design of syntax for oop,
I noticed a difference between
{polymorphic subtyping (polymorphs)
, evolutionary subtyping (evolvers)
} that would cause their syntax to differ:
. the polymorphs are exemplified by the numbers,
which include the subtypes {Q,R,N,Z,C,...}.
. an obj' of type"number needs to recognize
all the binary operations (biop's)
that are recognized by any of its subtypes; [1]
this implies that a subtype's set of biop's
can never be an extension of
its supertype's biop set
-- it must instead be a subset .
. this is in stark contrast to evolvers
where a subclass's set of operations
come from not only inheriting those of superclass's
but also by declaration of new operations .
1:
proving (using number as an example)
the supertype of a polymorph needs to recognize
the union of all its subtypes' operations:
. any time a binary operation occurs on
on an arbitrary pair of subtypes of number,
the most general response must be
to ask the supertype how to handle
any combination of subtyping in
{Q,R,N,Z,C,...}x{Q,R,N,Z,C,...} .
. even though there may be biop's
that only one subtype can perform,
in the general case
-- with dynamically changing subtypes
and user-defined polymorphs --
the only modular approach
is to leave it up to the supertype
to decide on whether a pair of subtypes
can legally be used by a given biop .
. the alternative to modularity
is to reprogram the compiler
to know what the supertype's job is,
so that it can supply that code implicitely .
. that might make sense for numbers,
but can compilers be changed in the general case?
(eg, with plugins); otherwise,
polymorphs need to put that code
in their supertype's body .

. the compiler should be able to use
the supertype's body, in a high-level way,
for optimizing code;
eg, if every twin pair (M,M) results in
delegating the implementation to M's method,
then in-line code could include
a run-time check for whether a pair were twins .