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 Path: g2news2.google.com!postnews.google.com!g10g2000cwb.googlegroups.com!not-for-mail From: "Ludovic Brenta" Newsgroups: comp.lang.ada Subject: Re: Instantiating private types with discriminants? Date: 9 May 2006 06:56:53 -0700 Organization: http://groups.google.com Message-ID: <1147183013.687672.246320@g10g2000cwb.googlegroups.com> References: NNTP-Posting-Host: 212.190.145.10 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1147183020 6014 127.0.0.1 (9 May 2006 13:57:00 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 9 May 2006 13:57:00 +0000 (UTC) In-Reply-To: User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; SunOS sun4u; fr-FR; rv:1.6) Gecko/20040116,gzip(gfe),gzip(gfe) X-HTTP-Via: 1.1 SEVPXS01 Complaints-To: groups-abuse@google.com Injection-Info: g10g2000cwb.googlegroups.com; posting-host=212.190.145.10; posting-account=ZjNXewwAAADyBPkwI57_UcX8yKfXWOss Xref: g2news2.google.com comp.lang.ada:4150 Date: 2006-05-09T06:56:53-07:00 List-Id: rick H a =E9crit : > Hello, > > I'm slowly learning Ada for my own amusement, and I've ground to a halt > trying to understand something. If some kind sole could explain it to > me, I'd be very grateful. > > I've defined two types, each with a descriminant, and each with its own > access type. One of the type's implementations is, however, private: > > package Discrim is > type Type_A (Param : Integer :=3D 100) is null record; > type Type_A_Ptr is access Type_A; > > -- same as above, but implementation now private... > type Type_B (Param : Integer :=3D 100) is private; > type Type_B_Ptr is access Type_B; > private > type Type_B (Param : Integer :=3D 100) is null record; > end Discrim; > > > When I use "new" on two variables declared as Type_A_Ptr and Type_B_Ptr, > one requires a type conversion for the discriminant, whereas the other > requires a qualified expression: > > with Discrim; use Discrim; > procedure Use_Discrim is > A : Type_A_Ptr; -- public implementation > B : Type_B_Ptr; -- private implementation > begin > A :=3D new Type_A'(Param =3D> 100); -- qualified expression > B :=3D new Type_B (Param =3D> 123); -- type conversion > end Use_Discrim; > > So, my question to the experts is: Why does "privatising" a type's > details change the way that you "new" instantiations of it? Actually, the declaration of B is not a type conversion; it is an allocator that uses a subtype_mark, as opposed to a qualified_expression (see ARM 4.8(2)). Use_Discrim sees all the components of Type_A (there is only one: the discriminant), and so the qualified_expression is legal. But you could also use an allocator with a subtype_mark, so it is incorrect to say that A *requires* a qualified_expression; it only *allows* one: A :=3D new Type_A (Param =3D> 100); -- legal In contrast, Use_Discrim does not see the components of Type_B other than the discriminant, so doesn't know if there are any, and so the qualified_expression'aggregate (defined in 4.7(2)) would be illegal, since aggregates must contain one expression for each component, per 4=2E3.1(9). --=20 Ludovic Brenta.