From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,604e0f87aa06eab6 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-04-01 23:37:51 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!iad-peer.news.verio.net!news.verio.net!fu-berlin.de!uni-berlin.de!tar-alcarin.cbb-automation.DE!not-for-mail From: Dmitry A. Kazakov Newsgroups: comp.lang.ada Subject: Re: Imitation is the sincerest form of flattery Date: Wed, 02 Apr 2003 09:37:49 +0200 Message-ID: References: <5115eb96.0303232053.2fcc7d78@posting.google.com> <5115eb96.0303242148.57027600@posting.google.com> <6Y_fa.5102$kU.534@nwrdny01.gnilink.net> NNTP-Posting-Host: tar-alcarin.cbb-automation.de (212.79.194.111) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: fu-berlin.de 1049269069 4604389 212.79.194.111 (16 [77047]) X-Newsreader: Forte Agent 1.8/32.548 Xref: archiver1.google.com comp.lang.ada:35879 Date: 2003-04-02T09:37:49+02:00 List-Id: On Tue, 01 Apr 2003 14:38:08 GMT, "Frank J. Lhota" 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