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: 103376,e5bfd51af02edca2 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Re-exporting primitive operations of a private type (like "-", and 'min) Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.14.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: Date: Sun, 30 Oct 2005 09:57:27 +0100 Message-ID: <1v9k0ezbwyz6o.1dyyxzvm1mezv.dlg@40tude.net> NNTP-Posting-Date: 30 Oct 2005 09:57:25 MET NNTP-Posting-Host: 58ae7abf.newsread2.arcor-online.net X-Trace: DXC=`DGV2LfF;bBbSWda:jMWf@Q5U85hF6f;DjW\KbG]kaMHQ>n?D9BSA]L=0DeU@Y_YOL[6LHn;2LCVN[ On Sat, 29 Oct 2005 21:19:27 GMT, Anonymous Coward wrote: > I'm bothered by the fact that the primitive operations of a parent are > not inherited in a private type. They are but in the view where inheritance happens. In your example it happens in the private view. > In particular, the basic arithmetic > operations are lost, like "+", "-", 'min, 'max, etc. "+' and "-" are rather hidden. > There seems to > be no clean way to re-export these operations, Yep. That's because the original operation cannot be named. Otherwise, one could just rename new "-" to the old one. As for attributes, it is another case, they cannot be user-defined at all. > Redefining "-" is an annoyance. In general, the problem is that old-fashioned way emerged before Ada became OO. Private_Distance_Type is a numeric type. That should be its *public* contract. But in Ada it is impossible to specify things like this for non-tagged types [outside generics, to be precise.] The compiler cannot recognize the programmer's intent from a bunch of operations declared in the public part. So it does not. Therefore when in the private part Private_Distance_Type gets implemented as a clone of a numeric type, the compiler treats public "-" as a different operation declared. [ I'm not sure if interfaces of Ada 2005 might help here. Let's wait for a working compiler. ] Anyway, you could go this way: ... private type Most_Private_Distance_Type is new Public_Distance_Type; function Sub (Left, Right : in Most_Private_Distance_Type) return Most_Private_Distance_Type renames "-"; -- Renaming "as-declaration" creates a new primitive operation Sub type Private_Distance_Type is new Most_Private_Distance_Type; -- Both "-" and Sub are inherited, but "-" gets hidden by "-" -- declared in the public part function "-" (Left, Right : in Private_Distance_Type) return Private_Distance_Type renames Sub; -- Renaming "as-body" implements public "-" through private "-" -- via Sub Warning, this may crash GNAT 3.15p which has many bugs in visibility rules (let language lawyers correct me if I'm wrong and the above is illegal.) I didn't try such things with GNAT GPL but it is even more buggy. (:-() > I'm not even sure how to redefine > attribute operations like 'min. Suggestions? They aren't "normal" operations, as they should be, so forget about them. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de