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,185d6eb35f7cb1d6 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!d4g2000prg.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Private type definition must be definite : but why ? Date: Mon, 3 Mar 2008 08:29:16 -0800 (PST) Organization: http://groups.google.com Message-ID: <549a45f2-e4f3-4d24-84a0-4f59290c4c18@d4g2000prg.googlegroups.com> References: <074b2c5d-289c-42b1-bbf5-de9354f0ddcf@c33g2000hsd.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1204561756 2310 127.0.0.1 (3 Mar 2008 16:29:16 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 3 Mar 2008 16:29:16 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: d4g2000prg.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:20174 Date: 2008-03-03T08:29:16-08:00 List-Id: On Mar 1, 4:37 pm, "Hibou57 (Yannick Duch=EAne)" wrote: > Oops, sorry.... I was to much speedy to see a trouble here. > > I just have to use an unknown discriminant part (beceause it is > private), thus just have to do > > > package Xxx > > type Data_Row_Type(<>) is private; > > ... > > private > > type Data_Row_Type is new String; > > ... > > end Xxx; > > And it works, and every body's happy... me first :D > > Well, to be honest, I still do not understand why the user have to > know there is are unknow discriminants somewhere..... the user does > not need to know. The "user" has to know that there are unknown *constraints* (which could be discriminants, or could, as in this case, be array constraints), so that the user knows that you can't declare a variable (or other object) of that type without adding constraints. This is illegal: X : String; since you have to put array constraints on it. And if your program looks like this: package Xxx is type Data_Row_Type is private; private DO NOT LOOK IN HERE end Xxx; with Xxx; package Yyy is Z : Xxx.Data_Row_Type; end Yyy; If Data_Row_Type could be a "new String", you wouldn't be able to tell that Z is illegal without looking in the private part of Xxx, and you're not allowed to look at that. That's what Bob referred to as "breaking privacy". In this case: package Xxx is type Data_Row_Type(<>) is private; private DO NOT LOOK IN HERE end Xxx; with Xxx; package Yyy is Z : Xxx.Data_Row_Type; -- ILLEGAL end Yyy; Now Z is illegal, and the "user" can tell that without having to look in the private part of Xxx. That would make it OK for Data_Row_Type to be declared as a String. When you declare a private type, you'll need to ask: Does your design require that users of the package declare objects of that type? If the answer is "no", then you should put (<>) on the declaration so that you can make the private type be anything you want. P.S. If you really need Data_Row_Type to be a string and you need your users to be able to declare objects of the type, consider Ada.Strings.Bounded or Ada.Strings.Unbounded. -- Adam