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 Path: border1.nntp.dca3.giganews.com!backlog4.nntp.dca3.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nac.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!news.mixmin.net!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Making sense of predicates Date: Tue, 22 Oct 2013 09:57:21 +0200 Organization: cbb software GmbH Message-ID: References: <87iowprctp.fsf@adaheads.sparre-andersen.dk> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: IenaDxMXK2hi7fvYcb+MlQ.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 X-Original-Bytes: 2834 Xref: number.nntp.dca.giganews.com comp.lang.ada:183694 Date: 2013-10-22T09:57:21+02:00 List-Id: On Tue, 22 Oct 2013 09:20:50 +0200, Jacob Sparre Andersen wrote: > Dmitry A. Kazakov wrote: > >> Considering this: >> >> type T is tagged null record; >> procedure P (X : T); >> >> type S is new T with null record; >> procedure Q (X : T); >> >> subtype Subclass is T'Class with >> Dynamic_Predicate => Subclass in S'Class; >> -- Should have been Static_Predicate, but illegal >> >> Now: >> >> X : Subclass := S'(null record); >> begin >> X.P; >> X.Q; -- Illegal >> >> Well, predicates were not supposed to work in an intelligent way, so >> why not to add a kind that will? > > But they do. > > * Predicates limit the set of possible values of a type. Which definitely applies to Subclass. The set of values of Subclass is narrowed from T'Class to its proper subset S'Class. BTW, intelligence when limiting values set is a big issue by itself. It is enough to mention the Circle-Ellipse controversy. >> There are number of cases where this would be very useful. E.g. smart >> pointers: >> >> type T1 is tagged ...; >> type T1_Ptr is access all T1'Class; >> type H1 is new Ada.Finalization.Controlled with record -- Handle type >> Ptr : T1_Ptr; >> end record; >> >> type T2 is new T1 with ...; >> >> Presently it is impossible to derive H2 from H1 constrained to point >> to T2'Class. (Neither it were possible with implicit dereferencing) >> >> With the above, one would create a subtype of H1 constrained to >> T2'Class and then derive from it (better in one step, of course). > > I think I understand what you want. I suspect that it would be rather > hard to implement in a compiler. Do you have an idea for how it could > be done? By reworking Ada type system, which never will happen. I thought that maybe a more subtle way could be to bend some recently added patches in a useful way. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de