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 autolearn=unavailable autolearn_force=no version=3.4.4 Path: border1.nntp.ams.giganews.com!nntp.giganews.com!weretis.net!feeder1.news.weretis.net!feeder4.news.weretis.net!gandalf.srv.welterde.de!news.jacob-sparre.dk!loke.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: Jacob Sparre Andersen Newsgroups: comp.lang.ada Subject: Re: Making sense of predicates Date: Tue, 22 Oct 2013 09:20:50 +0200 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: <87iowprctp.fsf@adaheads.sparre-andersen.dk> References: NNTP-Posting-Host: monowall.adaheads.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: loke.gir.dk 1382426451 11339 86.48.41.195 (22 Oct 2013 07:20:51 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Tue, 22 Oct 2013 07:20:51 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) Cancel-Lock: sha1:7Z5BrtABg4t31WbTrMKFdhCbeQE= Xref: number.nntp.dca.giganews.com comp.lang.ada:183692 Date: 2013-10-22T09:20:50+02:00 List-Id: 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. * Extensions expand the set of possible values of a type. You just have to use the right tool for the job. > 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? (Just asking for fancy stuff without thinking if it is possible is something we should leave to architects.) Greetings, Jacob -- "War does not determine who is right - only who is left." -- Bertrand Russell