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,dad94612ff745427 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!news4.google.com!news.glorb.com!feeder.xsnews.nl!feeder1.cambrium.nl!feed.tweaknews.nl!194.100.2.60.MISMATCH!fi.sn.net!newsfeed2.fi.sn.net!feeder2.news.jippii.net!feeder1.news.jippii.net!nntp.inet.fi!inet.fi!newsfeed1.nokia.com!news1.nokia.com!not-for-mail From: rick H Subject: Re: Instantiating private types with discriminants? Newsgroups: comp.lang.ada References: Organization: home User-Agent: tin/1.8.1-20060215 ("Mealasta") (UNIX) (CYGWIN_NT-5.1/1.5.19(0.150/4/2) (i686)) Message-ID: Date: Wed, 10 May 2006 07:42:02 GMT NNTP-Posting-Host: 172.26.210.110 X-Complaints-To: newsmaster@nokia.com X-Trace: news1.nokia.com 1147246922 172.26.210.110 (Wed, 10 May 2006 10:42:02 EET DST) NNTP-Posting-Date: Wed, 10 May 2006 10:42:02 EET DST Xref: g2news2.google.com comp.lang.ada:4169 Date: 2006-05-10T07:42:02+00:00 List-Id: Dmitry A. Kazakov wrote: > On Tue, 09 May 2006 14:48:44 GMT, rick H wrote: >> Var_A : Access_T; -- could be "new Type_A" or a "new Type_B" >> begin >> -- Var_A := new Type_A' (Data => 100); >> Var_A := new Type_B' (Data => 100.0); >> >> -- problem line: >> if Var_A'Tag = Type_A'Tag then >> Ada.Integer_Text_IO.Put ( Type_A (Var_A.all).Data); >> elsif Var_A'Tag = Type_B'Tag then >> Ada.Float_Text_IO.Put ( Type_B (Var_A.all).Data); >> end if; >> end Simple_Case; > > You can do: > > if Var_A.all in Type_A then > > which is cleaner, and requires no reference to tags. Thanks to everyone for their help regarding the tags - I understand that now. > > BTW, You should probably make Put a primitive operation of General_T. Then > the whole could look like simply: > > Put (Var_A.all); -- Do what have to be done > I'm still a bit new to Ada terminology - does "making Put a primitive operation" mean doing this kind of thing with a generic package... type Fred is new Integer; package Fred_IO is new Ada.Text_IO.Integer_IO (Fred); use Fred_IO; If that's right - how would I do this in my example? I'm puzzled because Var_A.all.Data will resolve to either an Integer or a Float at run-time. Have I got to declare two new packages - one against Integer_IO and one for Float_IO and let the dispatcher get it right at run-time? -- Rick