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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "J-P. Rosen" Newsgroups: comp.lang.ada Subject: Re: Unknown constraints and type composition Date: Fri, 15 Jun 2018 07:13:38 +0200 Organization: Adalog Message-ID: References: NNTP-Posting-Host: XdjV4tYMtFfMKGpv0MuDzQ.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 Content-Language: fr Openpgp: preference=signencrypt X-Notice: Filtered by postfilter v. 0.8.3 Xref: reader02.eternal-september.org comp.lang.ada:53111 Date: 2018-06-15T07:13:38+02:00 List-Id: Le 14/06/2018 à 19:53, Jeffrey R. Carter a écrit : > On 06/14/2018 05:37 PM, Alejandro R. Mosteo wrote: >> I think I have read somewhere that types with unknown constraints are >> a good way of ensuring you (or your users) don't end with >> uninitialized values: >> >> types Whatever (<>) is [limited] private; >> >> function Create return Whatever; > > It's one way. There are others that might be better. Unknown > discriminants are more for generic formal types, to show that the > generic accepts indefinite actual types. > > One way to deal with this is to make the full type a record with > reasonable defaults for all the components. This works for all versions > of the language. > Even better, the default can be a raise expression (or a function that raises an exception for pre-2012), so no uninitialized object can be created. This is a run-time check, but a decent compiler would warn you at compile time. -- J-P. Rosen Adalog 2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00 http://www.adalog.fr