comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Making sense of predicates
Date: Tue, 22 Oct 2013 09:57:21 +0200
Date: 2013-10-22T09:57:21+02:00	[thread overview]
Message-ID: <bit6qebfxmq5.kf31w4ou1cqy.dlg@40tude.net> (raw)
In-Reply-To: 87iowprctp.fsf@adaheads.sparre-andersen.dk

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


  reply	other threads:[~2013-10-22  7:57 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-21 19:51 Making sense of predicates Dmitry A. Kazakov
2013-10-22  4:35 ` Randy Brukardt
2013-10-22  8:19   ` Dmitry A. Kazakov
2013-10-22 12:53     ` Georg Bauhaus
2013-10-22 13:38       ` Dmitry A. Kazakov
2013-10-22 20:38         ` Georg Bauhaus
2013-10-24  4:03     ` Randy Brukardt
2013-10-24  7:26       ` Dmitry A. Kazakov
2013-10-22  7:14 ` Shark8
2013-10-22  7:35   ` Jacob Sparre Andersen
2013-10-22 17:26     ` Shark8
2013-10-23  7:56       ` Jacob Sparre Andersen
2013-10-24  3:58       ` Randy Brukardt
2013-10-22  8:11   ` Dmitry A. Kazakov
2013-10-22  7:20 ` Jacob Sparre Andersen
2013-10-22  7:57   ` Dmitry A. Kazakov [this message]
2013-10-22 14:52     ` Dan'l Miller
2013-10-22 16:30       ` Dmitry A. Kazakov
2013-10-22 17:15         ` Dan'l Miller
2013-10-22 19:26           ` Dmitry A. Kazakov
2013-10-22 19:49             ` J-P. Rosen
2013-10-22 21:30             ` Dan'l Miller
2013-10-23  9:25               ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox