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-Thread: a07f3367d7,7ff1de84a8945e80 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!feeder.news-service.com!feeder.erje.net!news.mixmin.net!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Access types as parameters Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <521c4843-d40f-4545-9e80-ca725e847090@h21g2000yqa.googlegroups.com> <8410fc60-9b8a-4f82-92fc-622a6bbe5931@i18g2000pro.googlegroups.com> <8880c3d0-a07f-4d4e-ac87-372014598576@d15g2000prc.googlegroups.com> <4a83d018$0$26303$4f793bc4@news.tdc.fi> <4a847400$0$26304$4f793bc4@news.tdc.fi> <4a852df2$0$26317$4f793bc4@news.tdc.fi> <1jrxo2acn8evc.x3wfcmp4etbo.dlg@40tude.net> <4a858af5$0$24774$4f793bc4@news.tdc.fi> <4a870a5b$0$26302$4f793bc4@news.tdc.fi> <4a87d705$0$24771$4f793bc4@news.tdc.fi> Date: Sun, 16 Aug 2009 14:38:00 +0200 Message-ID: NNTP-Posting-Date: 16 Aug 2009 14:37:56 CEST NNTP-Posting-Host: 1730c3fe.newsspool1.arcor-online.net X-Trace: DXC=1@hHQZiKkl?n`gW2MTm]<3ic==]BZ:af>4Fo<]lROoR1^YC2XCjHcb9UD^3igdJI9O@UIaP?o0FkkD8;1WZ3; X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:7827 Date: 2009-08-16T14:37:56+02:00 List-Id: On Sun, 16 Aug 2009 12:52:53 +0300, Niklas Holsti wrote: > Dmitry A. Kazakov wrote: >> On Sat, 15 Aug 2009 22:19:41 +0300, Niklas Holsti wrote: >> >>> Dmitry A. Kazakov wrote: >>>> On Fri, 14 Aug 2009 19:03:52 +0300, Niklas Holsti wrote: >>>> >>>>> Of course not, only the point (within the class) of the implementation >>>>> of the currently executing, (possibly) inherited operation (the caller) >>>>> is determined. The actual type, as you well know, is any type in >>>>> T'Class, although it is written "T" in the operation profile. >>>> No, the actual type is T, just because the operation declaration tells so. >>> This seems to be the origin of our disagreement. You want to view the >>> object as of type T, although at run-time it may be a T-view of an >>> object of a derived type S. This means that you cannot redispatch. But >>> this does not entitle you to call redispatching "bad" in general. >> >> Ada does not allow other cases, I mean dispatching while preserving a >> class-wide view on the object. What comes in mind: >> >> 1. procedure Foo (X : T'Class) is >> begin >> if X in S'Class then >> Bar (X); -- Now "dispatch" again >> elsif X in Q'Class then >> Baz (X); -- "dispatch" again >> >> This is a form of re-dispatch since the tag of X is analyzed twice. > > I don't see how this relates to our subject. Just an example of how type tag is dealt with while keeping a class-wide view of the object. Re-dispatching is no different. You publicly check the tag, declare the result of T, but keep in the sleeve S. Let's play by rules... (:-)) > Yes, that code looks at the > tag of X. Are you saying that any inspection of the tag of an object is > "bad design", except for the case of "basic" dispatching? With a high degree of probability it is. In all cases I have to check tag I feel myself guilty. > Although I sometimes do it, I don't much like to inspect tags, as in Foo > above, because it couples the logic of a class-wide operation to the > existence and properties of certain explicitly named sub-classes, which > is fragile. But a redispatching call is not fragile in this way. It is fragile because it has a behavior that is not determined by the values attributed to the type T. Its behavior is determined by the values of T'Class, which is an open-ended set. >> Re-dispatch is a hack. What do you do is >> semantically not inheritance but overriding with an instance of a generic >> body, or some class-wide body. I think this is the key issue. > > I'm sorry, I don't understand why it is "semantically not inheritance". Type S inherits F from T by composition of T.F with a type conversion: S.F = T.F o S_from_T That is the only way to define it in a typed language where S and T are distinct types. This is also how Ada defines it. Any primitive operation gets "re-declared" when you derive S from T. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de