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-Thread: 103376,e5bfd51af02edca2,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!cyclone1.gnilink.net!spamkiller.gnilink.net!gnilink.net!trnddc04.POSTED!20ae255c!not-for-mail Newsgroups: comp.lang.ada From: Anonymous Coward Subject: Re-exporting primitive operations of a private type (like "-", and 'min) Message-Id: User-Agent: slrn/0.9.7.4 (Linux) Date: Sat, 29 Oct 2005 21:19:27 GMT NNTP-Posting-Host: 141.149.78.234 X-Complaints-To: abuse@verizon.net X-Trace: trnddc04 1130620767 141.149.78.234 (Sat, 29 Oct 2005 17:19:27 EDT) NNTP-Posting-Date: Sat, 29 Oct 2005 17:19:27 EDT Xref: g2news1.google.com comp.lang.ada:6047 Date: 2005-10-29T21:19:27+00:00 List-Id: I'm bothered by the fact that the primitive operations of a parent are not inherited in a private type. In particular, the basic arithmetic operations are lost, like "+", "-", 'min, 'max, etc. There seems to be no clean way to re-export these operations, or am I missing something? Here is some sample code: [distance.ads] package Distance is type Public_Distance_Type is new Float; procedure Some_Procedure (Sample_Variable : in Public_Distance_Type); type Private_Distance_Type is private; Zero_Distance : constant Private_Distance_Type; Large_Distance : constant Private_Distance_Type; function "-" (Left, Right : in Private_Distance_Type) return Private_Distance_Type; private type Private_Distance_Type is new Public_Distance_Type; Zero_Distance : constant Private_Distance_Type := 0.0; Large_Distance : constant Private_Distance_Type := 999_999_999.0; end Distance; [distance.adb] package body Distance is function "-" (Left, Right : in Private_Distance_Type) return Private_Distance_Type is begin --This is ugly. Isn't there a way to declare this --operation without redefining it? The type casting --is also a nuissance, but the compiler warns of --infinite loops if casting is not used. return Private_Distance_Type(Public_Distance_Type(Left) - Public_Distance_Type(Right)); end "-"; procedure Some_Procedure (Sample_Variable : in Public_Distance_Type)is begin --This was another simple test to see whether we can --inherit explicitly declared public operations. null; end Some_Procedure; end Distance; [use_distance.adb] with Distance; procedure Use_Distance is Public_Distance : Distance.Public_Distance_Type; Private_Distance : Distance.Private_Distance_Type; use type Distance.Private_Distance_Type; use type Distance.Public_Distance_Type; begin Public_Distance := Distance.Public_Distance_Type'Min(-5.0,7.0); --The following line fails to compile because --'min is not inherited. -- --Private_Distance := Distance.Private_Distance_Type'Min -- (Distance.Zero_Distance,Distance.Large_Distance); Distance.Some_Procedure (Sample_Variable => Public_Distance); --The following line fails to compile because --Some_Procedure is not inherited. -- --Distance.Some_Procedure (Sample_Variable => Private_Distance); --This line compiles because it was redefined explicitly -- Private_Distance := Distance.Large_Distance - Distance.Zero_Distance; end Use_Distance; --- Redefining "-" is an annoyance. I'm not even sure how to redefine attribute operations like 'min. Suggestions?