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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,dbbbb21ed7f581b X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!newsfeed.straub-nv.de!noris.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Operation can be dispatching in only one type Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.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: <025105f2-5571-400e-a66f-ef1c3dc9ef32@g27g2000yqn.googlegroups.com> <4b150869$0$6732$9b4e6d93@newsspool2.arcor-online.net> <18vlg095bomhd.8bp1o9yysctg$.dlg@40tude.net> <4b152ffe$0$7615$9b4e6d93@newsspool1.arcor-online.net> <19nhib6rmun1x$.13vgcbhlh0og9$.dlg@40tude.net> <4b1557d0$0$7623$9b4e6d93@newsspool1.arcor-online.net> <4b15bf2b$0$7623$9b4e6d93@newsspool1.arcor-online.net> <1jcbtmi5rztyp$.norvlhez9i9$.dlg@40tude.net> <4b179ffb$0$6591$9b4e6d93@newsspool3.arcor-online.net> <1gcigitaii0u0.1psu2vj52e66g$.dlg@40tude.net> Date: Tue, 8 Dec 2009 10:12:03 +0100 Message-ID: NNTP-Posting-Date: 08 Dec 2009 10:12:03 CET NNTP-Posting-Host: 9937b91b.newsspool4.arcor-online.net X-Trace: DXC=b49NimDLYnd]BlmkiiU@Bi4IUKonadc08aK>Tn X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:8346 Date: 2009-12-08T10:12:03+01:00 List-Id: On Tue, 8 Dec 2009 05:30:30 +0100, stefan-lucks@see-the.signature wrote: > On Mon, 7 Dec 2009, Randy Brukardt wrote: > >> "Dmitry A. Kazakov" wrote in message > >>> Why not to allow such constraints for subtypes? E.g. >>> >>> subtype Valid_Window_Type is Window_Type when Is_Valid; >>> >>> then simply: >>> >>> procedure Do_Something (Window : Valid_Window_Type; ...) >> >> That's also under consideration, > > Great! > > Isn't that essentially the same as the invariants in Eiffel? I see differences. Both Window_Type and Valid_Window_Type are visible. Eiffel invariant deals with one type. Further the invariant is an implementation detail normally invisible for the clients. Subtype is a publicly declared constraint (contract). >> but there are some problems with it. One >> problem is that such types are very confusing in array indexes/slices (do >> the values all participate or just the ones that pass the predicate?) > > One way to solve^H^H^H^H^H^H circumvent this problem would be to prohibit > that kind of subtyping for discrete types. In Dmity's example above, > Window_Type is likely to be a record (probably a tagged one). If it is not > a discrete type, you can't use it as an array index. :-) Well, it would be nice not to limit this to only tagged types. > In any case, you definitively would not want to allow that kind of type > for array indexes, if only the values which the predicate being true is > allowed. How would you efficiently implement something like > > subtype Primes is Positive when Is_Prime; > A: array (Primes (10_000 .. 20_000)) of T; -- 10_001 primality tests I assume the above should be: A: array (Primes'Val (10_000) .. Primes'Val (20_000)) of T; > B: array (Primes (Start .. Stop)) of T; -- Start-Stop+1 such tests > -- possibly at runtime And this: B: array (Primes (Start) .. Primes (Stop)) of T; However the rules determining the subtype of the range are not clear. The main problem is that there is no range types and their subtype to clarify the issue: Positive'(1)..Positive'(2) is this positive range or Integer range? Same with above, if ranges fall back to the base type ranges, there will be no problem, but also the semantics of the declarations would change to: A: array (Integer (Primes'Val (10_000)) .. Integer (Primes'Val (20_000))) of T; This is the actual problem to me, not the performance issues. The programmer packing a DVD playback into the subtype constraint should know what he is doing. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de