From: Shark8 <onewingedshark@gmail.com>
Subject: Musing on defining attributes and the ability to define an "abstract type X"-interface.
Date: Wed, 19 Jul 2017 17:06:35 -0700 (PDT)
Date: 2017-07-19T17:06:35-07:00 [thread overview]
Message-ID: <9617c73b-e23e-405b-8544-4d17e7e3ad61@googlegroups.com> (raw)
Also, somewhat tangential to my post on user-defined attributes, if there were a way to define attributes could it perhaps be used to make an "abstract type" interface, allowing something like:
Abstract Type Array_Type is record
-- Not predefined attributes.
Function Index_Count return Positive;
Function Index_Type( Index : Positive := 1 ) return (<>); -- As in generic parameters.
-- Predefined Array Attributes.
Function First ( Index : Positive := 1 ) return Index_Type(Index)
with Pre => Index <= Array_Type'Index_Count;
Function Last ( Index : Positive := 1 ) return Index_Type(Index)
with Pre => Index <= Array_Type'Index_Count;
Function Length ( Index : Positive := 1 ) return Natural
is ( Integer'Succ(Array_Type'Last(Index) - Array_Type'First(Index)) );
Function Range ( Index : Positive := 1 ) return Range -- Not in current Ada.
is ( Array_Type'First(Index)..Array_Type'Last(Index) );
-- Predefined Subtype Attributes.
Function Alignment return Universal_Integer
with Post => Alignment'Result >= 0;
Function Definite return Boolean;
end record;
And, of course my example brings up points that would need to be addressed:
(1) How would we indicate that Array_Type has a non-null ordered set of indexers. [ Array_Type's Range attribute {1..X | x is the dimensionality of the array} ]
(2) How would we indicate the [sub]types of the indexes are not necessarily of the same [sub]type? [ex. Array(Integer,character) of X ]
(3) How would we indicate the "constrainedness" of a particular index? (Or does this matter?) [ex Array(Integer range <>,character) of X ]
(4) It seems ranges would have to become first-class types in order to satisfy the return-value of the Range attribute. (Though perhaps some compiler-magic like is done w/ Ada.Iterator_Interfaces and the for-loop might handle that...)
(5) It is uncertain whether making these inheritable would be good: on the plus side you could define an abstract-type that held the READ and WRITE and other common attributes and have a hierarchy of "type-classes".
(6) The exposure of heretofore conceptual types. (e.g. Universal_Integer)
(7) The exposure of the "type of a type".
(8) Would it be worth it for compiler-writers? Language maintainers? Language users? -- On the one hand being able to indicate explicitly that "definite type X" has *these* attributes while "Fixed-point type Y" has *those* attributes might be pretty nice... especially if we could make interfaces a bit more consistant. (e.g. allowing both Indefinite_Vector_Var'Length and Array_Var'Length.)
(9) On the user-side I think it would be great to be able to have the Ada.Containers.Vector Vector-type have a compatible interface to Array... we're halfway there with the Vector_Var'Iterate + For-loop anyway.
next reply other threads:[~2017-07-20 0:06 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-20 0:06 Shark8 [this message]
2017-07-20 7:52 ` Musing on defining attributes and the ability to define an "abstract type X"-interface Dmitry A. Kazakov
2017-07-20 16:37 ` Shark8
2017-07-20 17:40 ` Dmitry A. Kazakov
2017-07-20 20:12 ` Jacob Sparre Andersen
2017-08-04 3:05 ` Shark8
2017-08-04 6:48 ` Simon Wright
2017-08-04 7:10 ` Dmitry A. Kazakov
2017-08-05 0:17 ` Randy Brukardt
2017-08-05 6:25 ` Dmitry A. Kazakov
2017-08-05 16:51 ` Shark8
2017-08-05 17:18 ` Dmitry A. Kazakov
2017-08-05 21:29 ` Shark8
2017-08-06 7:04 ` Dmitry A. Kazakov
2017-08-07 23:06 ` Randy Brukardt
2017-08-08 17:28 ` Shark8
2017-08-09 1:12 ` Randy Brukardt
2017-08-09 18:17 ` G.B.
2017-08-07 23:12 ` Randy Brukardt
2017-08-08 8:10 ` Dmitry A. Kazakov
2017-08-09 0:44 ` Randy Brukardt
2017-08-09 6:55 ` Dmitry A. Kazakov
2017-08-09 23:22 ` Randy Brukardt
2017-08-10 7:02 ` Dmitry A. Kazakov
2017-08-11 0:40 ` Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox