From: Dmitry A. Kazakov <mailbox@dmitry-kazakov.de>
Subject: Re: Imitation is the sincerest form of flattery
Date: Wed, 02 Apr 2003 09:37:49 +0200
Date: 2003-04-02T09:37:49+02:00 [thread overview]
Message-ID: <uqcj8vcucbm80g6s758lj4112fje05sntq@4ax.com> (raw)
In-Reply-To: kvhia.20007$_14.1954@nwrdny02.gnilink.net
On Tue, 01 Apr 2003 14:38:08 GMT, "Frank J. Lhota"
<NOSPAM.lhota.adarose@verizon.net> wrote:
>It is not entirely clear how multiple dispatch would work with a function
>such as Max. Consider this version of the function:
>
> -- Assuming Integer is tagged and MD is allowed
> function Max (Left, Right : Integer'Class) return Integer'Class is
> begin
> if Left < Right then
I assume that "<" has to be MD and declared as:
function "<" (Left, Right : Integer) return Boolean;
Here is the first problem. It cannot be a primitive operation of
Boolean, which is also "tagged". So it should to be:
function "<" (Left, Right : Integer) return Boolean'Class;
But this is potentially inefficient because Boolean'Class is a large
object as compared with Boolean. It has the type tag. Probably one
should allow an explicit specification of contravariant /
non-dispatching parameters / results. Sort of:
function "<" (Left, Right : Integer) return Boolean'Base;
Here the result is contravariant/non-dispatching.
> return Right;
> else
> return Left;
> end if;
> end Max;
>
>Now assume we have the following declarations:
>
> type X_Integer is new Integer;
I assume that this is actually
type X_Integer is new Integer with null record;
> -- Specialized version of "<" for X_Integer ...
> function "<" ( Left, Right : in X_Integer ) return Boolean;
At the freezing point of X_Integer the compiler has to cry out: you
have overridden
function "<" (Left, Right : X_Integer) return Boolean'Base;
so you have to do it for
function "<" (Left : Integer; Right : X_Integer)
return Boolean'Base;
and
function "<" (Left : X_Integer; Right : Integer)
return Boolean'Base;
Otherwise, it is not clear how to deal with:
X : Integer;
Y : X_Integer;
...
X < Y
One should probably allow something like
function "<" (Left : X_Integer; Right : Integer)
return Boolean'Base renames Integer."<";
> X : X_Integer;
>
> type Y_Integer is new Integer;
> -- Specialized version of "<" for Y_Integer ...
> function "<" ( Left, Right : in Y_Integer ) return Boolean;
> Y : Y_Integer;
>
>Within Max( X, Y ), which version of "<" is used?
With siblings it becomes even worse. A solution as above, to require
that all possible combinations of parameter types be overriden, is
hard to imagine. X_Integer and Y_Integer might be declared in
different compilation units, so the error could appear only when the
units are with-ed. Freezing points passed. Nothing can be done. Full
stop.
Alternatives are:
1. It dispatches to Integer.">". I.e. it dispatches to the most
specific common base type.
2. It causes Constraint_Error. No dispatch on siblings.
Both are unsatisfactory in my view. There are indeed problems with MD.
---
Regards,
Dmitry Kazakov
www.dmitry-kazakov.de
next prev parent reply other threads:[~2003-04-02 7:37 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-03-14 17:22 Imitation is the sincerest form of flattery Robert C. Leif
2003-03-14 17:57 ` Warren W. Gay VE3WWG
2003-03-14 18:16 ` chris.danx
2003-03-14 18:17 ` Hyman Rosen
2003-03-15 14:18 ` Georg Bauhaus
2003-03-16 1:06 ` Hyman Rosen
2003-03-18 10:37 ` Georg Bauhaus
2003-03-18 15:34 ` Dmitry A. Kazakov
2003-03-19 11:12 ` Georg Bauhaus
2003-03-20 8:42 ` Dmitry A. Kazakov
2003-03-20 14:27 ` Frank J. Lhota
2003-03-21 8:44 ` Dmitry A. Kazakov
2003-03-21 17:16 ` Pascal Obry
2003-03-22 9:05 ` Dmitry A. Kazakov
2003-03-22 14:11 ` Pascal Obry
2003-03-22 23:12 ` AG
2003-03-23 9:01 ` Dmitry A. Kazakov
2003-03-23 8:51 ` Dmitry A. Kazakov
2003-03-24 16:52 ` Hyman Rosen
2003-03-24 18:10 ` Dmitry A. Kazakov
2003-03-24 18:33 ` Hyman Rosen
2003-03-25 5:04 ` Amir Yantimirov
2003-03-25 19:55 ` Dmitry A. Kazakov
2003-03-25 20:22 ` Hyman Rosen
2003-03-26 13:02 ` Dmitry A. Kazakov
2003-03-26 15:06 ` Hyman Rosen
2003-03-26 16:21 ` Dmitry A. Kazakov
2003-03-26 17:00 ` Hyman Rosen
2003-03-26 18:21 ` Bill Findlay
2003-03-26 18:40 ` Hyman Rosen
2003-03-22 10:01 ` Amir Yantimirov
2003-03-23 8:41 ` Dmitry A. Kazakov
2003-03-24 4:53 ` Amir Yantimirov
2003-03-24 18:10 ` Dmitry A. Kazakov
2003-03-25 5:48 ` Amir Yantimirov
2003-03-25 15:53 ` Frank J. Lhota
2003-03-25 16:44 ` Robert A Duff
2003-03-25 18:24 ` Frank J. Lhota
2003-03-25 20:06 ` Dmitry A. Kazakov
2003-03-27 19:45 ` Frank J. Lhota
2003-03-27 21:25 ` Pascal Obry
2003-03-28 13:34 ` Dmitry A. Kazakov
2003-04-01 14:38 ` Frank J. Lhota
2003-04-02 7:37 ` Dmitry A. Kazakov [this message]
2003-03-26 7:48 ` Amir Yantimirov
2003-03-26 13:35 ` Dmitry A. Kazakov
2003-03-26 7:32 ` Amir Yantimirov
2003-03-20 23:28 ` Matthew Heaney
2003-03-21 8:49 ` Dmitry A. Kazakov
2003-03-21 21:07 ` Georg Bauhaus
2003-03-22 9:04 ` Dmitry A. Kazakov
2003-03-22 10:05 ` AG
2003-03-22 15:25 ` Georg Bauhaus
2003-03-22 19:27 ` AG
2003-03-22 21:45 ` Vinzent Hoefler
2003-03-22 22:28 ` AG
2003-03-23 23:47 ` Robert A Duff
2003-03-28 16:34 ` Georg Bauhaus
2003-03-18 15:58 ` Hyman Rosen
2003-03-19 11:05 ` Georg Bauhaus
2003-03-23 11:31 ` Florian Weimer
2003-03-23 23:39 ` Hyman Rosen
2003-03-15 12:52 ` Florian Weimer
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox