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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1dcef85eb875c8db X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-06-11 23:05:22 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!fu-berlin.de!uni-berlin.de!b9a98.pppool.DE!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Dispatching to a common most special ancestor Date: Thu, 12 Jun 2003 08:08:02 +0200 Organization: At home Message-ID: References: Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: b9a98.pppool.de (213.7.154.152) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: fu-berlin.de 1055397921 16916634 213.7.154.152 (16 [77047]) User-Agent: KNode/0.7.1 Xref: archiver1.google.com comp.lang.ada:39024 Date: 2003-06-12T08:08:02+02:00 List-Id: Stephan Heinemann wrote: > Please have a look at the following code: [...] > I wanted Equals to be dispatched to the common object ancestor but > instead a constraint error is raised. How might I resolve this? There is a work-around for multiple dispatch. You might look at http://www.dmitry-kazakov.de/ada/components.htm which presumably does what you want. In short, you declare: function Equal ( Left : Object; Right : Object'Class; Flag : Boolean := False ) return Boolean; function Less ( Left : Object; Right : Object'Class; Flag : Boolean := False ) return Boolean; and then override, for instance Less: function Less ( Left : A_New_Object; Right : Object'Class; Flag : Boolean := False ) return Boolean is begin if ( Flag or else Right not in A_New_Object'Class or else Right in A_New_Object ) then -- Implement it here ... else -- Dispatch on the second parameter return not ( Less (Right, Left, True) or else Equal (Right, Left, True) ); end if; end Less; The idea is that you do something if Left :> Right, otherwise you redispatch through Right. For a commutative operation it is pretty straightforward. For a non-commutative (like Less) it is a little bit tricky, as the code shows. Beware, that the predefined "=" cannot be disallowed, so you cannot do function "=" (Left : Object; Right : Object'Class) is begin return Equal (Left, Right); end "="; because it would just overload the predefined one. -- Regards, Dmitry A. Kazakov www.dmitry-kazakov.de