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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,bdd718faa7c79f29 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-06-21 19:57:05 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!xmission!news-out.spamkiller.net!propagator2-maxim!news-in.superfeed.net!newsfeed01.tsnz.net!news.xtra.co.nz!53ab2750!not-for-mail From: "AG" Newsgroups: comp.lang.ada References: Subject: Re: Overlapping ranges X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Message-ID: <5W8Ja.43776$JA5.768297@news.xtra.co.nz> Date: Sun, 22 Jun 2003 14:58:05 +1200 NNTP-Posting-Host: 219.88.62.51 X-Complaints-To: newsadmin@xtra.co.nz X-Trace: news.xtra.co.nz 1056250625 219.88.62.51 (Sun, 22 Jun 2003 14:57:05 NZST) NNTP-Posting-Date: Sun, 22 Jun 2003 14:57:05 NZST Organization: Xtra Xref: archiver1.google.com comp.lang.ada:39549 Date: 2003-06-22T14:58:05+12:00 List-Id: "Mark A. Biggar" wrote in message news:My7Ja.54206$hz1.129990@sccrnsc01... > AG wrote: > > Assuming I have a package declaration like this: > > > > > > package range is > > type x1 is range 0..255; > > type x2 is range 127..2**15-1; > > end ranges; > > > > > > Is there a way to declare a function > > using that package that will accept > > values of either x1 or x2 (and nothing > > else) restricted to the range 127..255 ? > > You have a bug in your design abstraction. It's not a bug it's a feature -) > x1 and x2 are different > types and there is no way to declare a parameter with more then one > type. Exactly. And that's the problem - I'm looking for a way to declare a function [and/or whatever] that could handle values of either of the two [test-bed of course] types and, on top of that, impose range restrictions on the values passed in. > First option fix the abstraction: > > package range is > type xBase is range 0..2**15-1; > subtype x1 is xBase range 0..255; > subtype x2 is xBase range 127..2**15-1; > subtype x1x2Intersect is xbase range 127..255; Sorry, won't work. V1, V2 and V1x2 of the subtypes are all mutually assignment-compatible. How would the function know what you passed in? > If you really need two separate types: > > package range is > type xBase is range 0...2**15-1; > subtype x1x2Intersect is xBase range 127..255; > type x1 is new xBase range xBase'First..255; > type x2 is new xBase range 127..xBase'Last; > > function foo(p: x1x2intersect) return ...; > end ranges; That's a little bit better but: you've declared the intersect [sub]type as coming from the type xBase. What exactly does it have to do with derived types x1 & x2? > Another option is to use a discriminated record: No, sorry, let's not go there. I know it's possible but it's not exactly what I'm after ...