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!.POSTED!not-for-mail From: "Alejandro R. Mosteo" Newsgroups: comp.lang.ada Subject: Re: Unknown constraints and type composition Date: Fri, 15 Jun 2018 11:34:53 +0200 Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Fri, 15 Jun 2018 09:34:54 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="28f9812d2e4a4d571e566a6a5e6288c5"; logging-data="16185"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18gbn9O4u31CcuFo3JidPLT" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 Cancel-Lock: sha1:rOw2DY+D7Rx1nmGcSiKtRXytiZ8= In-Reply-To: Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:53118 Date: 2018-06-15T11:34:53+02:00 List-Id: On 15/06/2018 07:13, J-P. Rosen wrote: > 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. Interesting. So you can have the definite type, but you're forced to provide a initialization, and are warned about it. Seems one trick to remember, thanks!