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!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: Type Transcriptions Date: Mon, 21 Apr 2014 22:33:47 +0200 Organization: A noiseless patient Spider Message-ID: <87ha5m1kyc.fsf@ludovic-brenta.org> References: <53554D3F.8050009@shaw.ca> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: mx05.eternal-september.org; posting-host="86e5c4783148a3b3ed891f415b499473"; logging-data="23780"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+K0AJGxKkWsQoJ97m9RdJz" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:TVSd5B6g/nURPBQy80H79nD2u28= sha1:+D06R8Sqxp4hFCO752iQHjJDpM0= Xref: news.eternal-september.org comp.lang.ada:19475 Date: 2014-04-21T22:33:47+02:00 List-Id: Shark8 writes: > On 21-Apr-14 12:11, Yannick Duchêne (Hibou57) wrote: >> Le Mon, 21 Apr 2014 18:54:23 +0200, Brad Moore a >> écrit: >> >>> I'd suggest trying to make GenericAEADCipher a discriminated record >>> type, with the two length values as the discriminants, and then the >>> arrays are sized using the discriminants. No Generics needed. >>> >>> Brad >>> >> >> I guess Shark8 would already have figured it if this could be as simple. >> He says this, which is important: “certain class of record-type is >> dependent on the values in another record, yet distinctly separate”. >> With two separated things, a discriminant is not applicable. Or may be >> I've not understood. > > You have the right of it. > Using discriminants is the natural way to do it, but doing so would > (in actuality) break sticking to the spec as the record-type would > have fields which don't exist in the spec. > > I suppose the better way to phrase it is: > "Is it better to strictly stick to the spec, letting generic > instantiation take care of these 'extra-typal' parameters, *OR* doing > things the natural Ada way, and worrying about 'fixing-up' things in, > say, 'Input and 'Output operations." Ada 2012 has a very nice new feature: unchecked unions (clause B.3.3); it is a discriminated record with an aspect says that the discriminants are *not* in the record, but stored elsewhere instead. I have used them in my tiny Ada binding to the X C binding (XCB), like so: type Detail_T (Response_Type : Response_Type_T := Reply) is record case Response_Type is when Key_Press | Key_Release => Keycode : Interfaces.Unsigned_8; when Button_Press | Button_Release | Motion_Notify => Detail : Button_T; when others => Padding : Interfaces.Unsigned_8; end case; end record with Unchecked_Union; type Response_T (Sent : Boolean; Response_Type : Response_Type_T) is record Detail : Detail_T (Response_Type); [other components omitted] end record; for Response_T use record Sent at 0 range 7 .. 7; Response_Type at 0 range 0 .. 6; end record; This says that the Response_T has two discriminants, stored as the first two components, and that the second discriminant, Response_Type, also constrains the component Detail, but Detail does not contain a copy of this discriminant. This sounds awfully similar to the spec you're trying to implement :) In this case, Ada 2012 saves the day! -- Ludovic Brenta.