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=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.101.73.138 with SMTP id r10mr10429855pgs.124.1505255663060; Tue, 12 Sep 2017 15:34:23 -0700 (PDT) X-Received: by 10.36.250.140 with SMTP id v134mr46837ith.0.1505255663019; Tue, 12 Sep 2017 15:34:23 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!paganini.bofh.team!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!127no555262itw.0!news-out.google.com!p6ni211itp.0!nntp.google.com!127no555259itw.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 12 Sep 2017 15:34:22 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=76.113.16.86; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC NNTP-Posting-Host: 76.113.16.86 References: <364ff8e0-c7dd-4980-b19f-5d438edd8353@googlegroups.com> <7df81b3c-1fde-4395-8b9b-1a945820a7f7@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Type invariants and private extensions? From: Shark8 Injection-Date: Tue, 12 Sep 2017 22:34:23 +0000 Content-Type: text/plain; charset="UTF-8" Xref: news.eternal-september.org comp.lang.ada:48091 Date: 2017-09-12T15:34:22-07:00 List-Id: On Tuesday, September 12, 2017 at 2:09:08 PM UTC-6, Victor Porton wrote: > Jeffrey R. Carter wrote: > > > > > "I want to" is not the same as "there is no way to solve the problem in > > current Ada". Ada has a feature that provides exactly what you need. It's > > called a variant record. > > It is a tagged type. AFAIK, a type cannot be both a variant record and > tagged. You certainly can: Type Type_Enumeration is ( TInteger, TReal, TBoolean, Nothing ); Type Example( Item_Type : Type_Enumeration ) is tagged record case Item_Type is when TInteger => I : Integer; when TReal => R : Float range Float'Range; when TBoolean => B : Boolean; when Nothing => Null; end case; end record; > Moreover, the object in consideration is a wrapper over a certain C API. It > surely cannot be described in variant record terms. Sure it can; there's a reason that there's a separation between specification and body, part of which is so you can hide something like an interface to C and present something sensible to your program/clients. > Moreover, bindings may contain more than one row of values which can be > enumerated like an iterator. I am not sure if this can be expressed in terms > of a variant record. Variant records can have discriminants, too. (In fact, discriminants are half of how variant-records do their thing, the other half being the "internal case statement/construct".) > The proposed feature increases reliability of programming. It is undoubtful > that adding more type invariants increases reliability. I fail to see how you couldn't achieve this by use of (a) variant records, and (b) constrained subtypes. eg: SubType Integer_Example is Example( TInteger ); Function X(Input : Integer) Return Integer_Example;