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 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: operation can be dispatching in only one type Date: Mon, 23 Nov 2015 14:48:12 +0100 Organization: cbb software GmbH Message-ID: <127g5diox4xef$.1bc0ja7q2xobo.dlg@40tude.net> References: <1e4hyjazuvi88.159qsn7u0y067$.dlg@40tude.net> <817c092d-4c49-4b09-a116-6d27d4d20291@googlegroups.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: uuaYi8S0HktMvp6/JW1g+A.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:28505 Date: 2015-11-23T14:48:12+01:00 List-Id: On Mon, 23 Nov 2015 05:05:02 -0800 (PST), Serge Robyns wrote: > On Monday, 23 November 2015 12:29:55 UTC+1, Dmitry A. Kazakov wrote: >> On Mon, 23 Nov 2015 02:23:57 -0800 (PST), Serge Robyns wrote: >> >>> I'm facing an issue with Ada when it comes to use an operation on two >>> tagged types. >> >> You can use tagged types, they cannot be dispatching arguments though. That >> is a big difference. >> >>> However in C++ it does work as I expected. >> >> C++ has no multiple dispatch either. > > I'm not using multiple dispatching, I'm using "serial" dispatching. What > I'm trying to achieve is very close to the concept of a mix-in. Hmm, mix-in uses a class-wide that gets mixed in. Which is why you could dispatch on it. No class-wide, no dispatch. > The code in C++ is doing what I want to achieve. C++ code is broken, always broken, because C++ confuses T and T'Class and hence re-dispatches each time and every place (except for ctors). Ada's exact equivalent to void account::update_balance (account_balance& ab, money amount) is procedure Update_Balance (X : in out Account; AB : in out Account_Balance'Class, ...) Neither is dispatching in AB. Where is a problem? > Obviously there is a > potential "bug" as I can pass any balance to the operation, including ones > from another account. Re-dispatch is a potential bug because it ignores declared types. >> It is too late to declare a dispatching operation on T_Balance when you >> already used T_Balance as a type somewhere else, e.g. to instantiate a >> package. > > As I said that operation is not dispatching on T_Balance, the T_Account > operation will be dispatching. Which is good as T_Account is the type being declared. I don't see what is the problem. If Update_Balance should be a primitive operation of T_Balance, it must be declared so. At the declaration point of T_Balance there is no T_Account yet thus you could not use it there. Again, good, it is bad design to mix containers and elements of. You just are trying an unpattern, IMO. You can still inject an account interface there if you wanted: type Abstract_Account is limited interface ...; type T_Balance is ... procedure Update_Balance -- Primitive operation ( Account : in out Abstract_Account'Class; Balance : in out T_Balance; ... ); type T_Account is new Abstract_Account with ... > As with regards to callback constructs, this sounds like "ugly" workarounds IMHO. Possibly, but IMO because of an anti-OO design. What are operations of T_Balance. What are operations of T_Account? Types are useless without operations. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de