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!news1.google.com!news2.google.com!news.glorb.com!newscon02.news.prodigy.net!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Private type definition must be definite : but why ? Date: Sat, 01 Mar 2008 19:43:06 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <074b2c5d-289c-42b1-bbf5-de9354f0ddcf@c33g2000hsd.googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: pcls6.std.com 1204418587 1558 192.74.137.71 (2 Mar 2008 00:43:07 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Sun, 2 Mar 2008 00:43:07 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:qpFZzHXZ45yQdYDHlwB4KRVqx3c= Xref: g2news1.google.com comp.lang.ada:20160 Date: 2008-03-01T19:43:06-05:00 List-Id: ""Hibou57 (Yannick Duch�ne)"" writes: > Hello, hello... > > I'm trying to express something I can't express with Ada semantic : > >> package Xxx >> type Data_Row_Type is private; >> ... >> private >> type Data_Row_Type is new String; >> ... >> end Xxx; > > Bu I cannot do that, beceause a private type definition must be > definite. You can say "X : Integer;" but you cannot say "X : String;", because String is indefinite -- we don't know its size. If the above were legal, then you could say "X : Xxx.Data_Row_Type;". (In clients of Xxx, I mean.) But that won't work -- we don't know its size. It can't be illegal, because legality rules should not break privacy. One solution is to use "unknown discriminants": package Xxx type Data_Row_Type (<>) is private; ... private type Data_Row_Type is new String; ... end Xxx; This means that the full type might have unconstrained bounds or discriminants. (Array bounds are conceptually pretty-much the same thing as discriminants.) Now the private type is indefinite, So now "X : Xxx.Data_Row_Type;" is illegal -- without breaking privacy. Presumably you would have some constructor functions, so the client can say "X : Xxx.Data_Row_Type := Make_Data_Row (...);". > While I can do > >> package Xxx >> type Data_Row_Type is new String; >> ... >> end Xxx; > > I would like to understand the reason of this restriction. There is a > user view (the public part) and a compiler view (public part + private > part). What you call the "compiler view" is for code generation. Ada is designed so that the compiler need not peek at the private part for legality rules. That's a good thing, because it allows the programmer of Xxx to change the private part without worrying about breaking clients. - Bob