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: how to force the Small aspect of a new type derived from the generic formal type ? Date: Fri, 26 Jan 2018 12:13:30 +0100 Organization: A noiseless patient Spider Message-ID: References: <1aaa851e-495a-4dd4-8db7-0fd84ee8225f@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 26 Jan 2018 11:13:31 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="5ca1a45ca47851aacf17019e526d1e22"; logging-data="10912"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19k23wexre+0/nvr2qPQxEO" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 In-Reply-To: Content-Language: en-US Cancel-Lock: sha1:7iOcCJX4f0ory8fU7EhwDieudWY= Xref: reader02.eternal-september.org comp.lang.ada:50162 Date: 2018-01-26T12:13:30+01:00 List-Id: On 25/01/18 13:54, Mehdi Saada wrote: >> Either the teacher is asking for the impossible > > Actually the teacher isn't asking to do that: he asked at some point to make it generic, at and at another, to force the Small. I assumed we could do both. > >> you can't use most representation aspects on a type derived from a generic formal type. > > I understand. But with this statement: > type Modele is delta <> with SMALL => MODELE'DELTA; > I intend to pass a contract, so that only types whose Small is set the same as the Delta will be accepted as valid parameters. I SUPPOSED it works like this... I suppose now I was wrong ? > Unfortunately aspects+generics (or, in general +generics) is one of the points where Ada orthogonality breaks down. In exchange you get sane generics, when compared to macro templates. I'm saying this in a practical, user-experience sense, not as a language lawyer (which I'm not). You can somewhat mitigate this with generic package formals, or with the "type T is new Base with private" kind of formals. Even after many years of using Ada, I find the table in the following link a lifesaver from time to time: https://en.wikibooks.org/wiki/Ada_Programming/Generics#Generic_formal_types Incidentally, I wonder what good Ada cheatsheets are out there.