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 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread3.news.pas.earthlink.net.POSTED!a6202946!not-for-mail From: "Jeffrey R. Carter" Organization: jrcarter at acm dot org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Re-exporting primitive operations of a private type (like "-", and 'min) References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Sun, 30 Oct 2005 09:18:26 GMT NNTP-Posting-Host: 67.3.219.144 X-Complaints-To: abuse@earthlink.net X-Trace: newsread3.news.pas.earthlink.net 1130663906 67.3.219.144 (Sun, 30 Oct 2005 01:18:26 PST) NNTP-Posting-Date: Sun, 30 Oct 2005 01:18:26 PST Xref: g2news1.google.com comp.lang.ada:6052 Date: 2005-10-30T09:18:26+00:00 List-Id: Anonymous Coward wrote: > --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); The whole point of private types is that the only visible operations on them are assignment, equality and inequality, and any explicitly defined operations in the visible part of the package specification. Thus, 'Min is not defined for the type because it is not visibly a numeric or enumeration type. Some_Procedure is not defined for the type because you did not define such a procedure for the type. "-" is defined only because you did define "-" for the type, not because of its full type definition. You can have any full type definition for the type that allows assignment and equality. It could be an array of records. Again, the only visible operations for the type are assignment, equality, and those explicitly defined in the package. The full type declaration is not visible, and the fact that it gives the type certain operations not declared in the package specification does not change the set of visible operations. Those additional operations are only visible where the full type definition is visible. Another way of saying this is that the full type definition has no effect on the client's view of the type. > Redefining "-" is an annoyance. I'm not even sure how to redefine > attribute operations like 'min. Suggestions? Redefining a predefined operation such as "-" *is* a pain. The problem is that once you declare "-" for the type, that declaration hides the predefined operation, and there's no way to refer to the predefined operation after that. That's why you have to convert to a suitable numeric type, invoke the equivalent operation for that type, and then convert back to the private type. (Note that "casting" is not an Ada term. I presume from context that you were referring to type conversions.) However, you only have to define the operations once, so it's a limited amount of pain. It might be nice to have a way to define opaque numeric types, but, for better or worse, that's not a path that Ada took. It's lack is most often felt in defining generics. There are situations in which a generic could operate on any numeric type. Ada has no easy way to define such a generic. -- Jeff Carter "C++ is like jamming a helicopter inside a Miata and expecting some sort of improvement." Drew Olbrich 51