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.1 required=5.0 tests=BAYES_00,REPLYTO_WITHOUT_TO_CC, UNCLOSED_BRACKET autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,1cb75f0476fe2d1a X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!newsfeed-east.nntpserver.com!nntpserver.com!statler.nntpserver.com!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Half Constrained Array Types and Slices Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1q3lxr5byac4f$.x8dnc8mjzyj2.dlg@40tude.net> <1141313690.19791.1.camel@sonnenregen> Date: Thu, 2 Mar 2006 20:37:00 +0100 Message-ID: <11dl471sl1hwr$.112glc09jnpkb.dlg@40tude.net> NNTP-Posting-Date: 02 Mar 2006 20:37:00 MET NNTP-Posting-Host: 3a9114bf.newsread2.arcor-online.net X-Trace: DXC=6KUKfG@VKh3h^:`T28h7QiYGl2`^iK;;[6LHn;2LCV>[ On Thu, 02 Mar 2006 16:34:50 +0100, Georg Bauhaus wrote: > On Thu, 2006-03-02 at 09:34 +0100, Dmitry A. Kazakov wrote: >> On Thu, 02 Mar 2006 05:00:06 GMT, Jeffrey R. Carter wrote: > >>> type String (Length : Natural) is array (1 .. Length) of Character; >> >> Not only this. Discriminants for arrays would also allow nice things like: >> >> type Table (Element_Size : Natural) is >> array (...) of String (1..Element_Size); > > If you didn't dislike generics that much, > > generic > Element_Size: NATURAL; > package String_Tables is > > subtype SIZED_STRING is STRING(1.. Element_Size); > > type TABLE is array(POSITIVE range <>) of SIZED_STRING; > > end String_Tables; Nope: type Table (Element_Size : Natural) is array (...) of String (1..Element_Size); function Read_From_File (File : File_Type) return Table; function Write_To_File (File : File_Type; X : Table); -- Notice indefinite formal parameters and results are OK subtype Punched_Cards is Table (80); -- Subtypes are OK This is why I dislike generics. Each instance of String_Tables produces an independent type. So there is no either named type or objects of the class TABLE. ---- Note that this problem is known since Pascal. Strings in original Pascal were of different types, when they had different lengths. Ada 83 introduced the idea of unconstrained types to handle this nuisance. So different sizes induced subtypes rather than types. Though the latter were also possible using "type is new." Generics is not Ada! (:-)) -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de