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 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7f2ce8bda9cae4ab X-Google-Attributes: gid103376,public Path: controlnews3.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: "Must instantiate controlled types at library level." Why? Date: Fri, 21 May 2004 22:33:24 +0200 Organization: At home Message-ID: <2h77beF9tvamU1@uni-berlin.de> References: Reply-To: mailbox@dmitry-kazakov.de Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: news.uni-berlin.de 9Rl0PlhITuBnclRYcJpNvg69sccBI5/WltSyoU5Lh26ITbXvQ= User-Agent: KNode/0.7.2 Xref: controlnews3.google.com comp.lang.ada:755 Date: 2004-05-21T22:33:24+02:00 List-Id: Georg Bauhaus wrote: > Dmitry A. Kazakov wrote: > > : Technically what is needed is abstract array interfaces, abstract > : index types, discriminants for all types, an ability to put type tags > : and disctiminants in a dope separate from the value, pure compile-time > : subprograms to evaluate does, supertypes. Give me that, then ask (:-)) > > function item_at (a: Array'type; pos: Index'type) return Element'type; > > Like this? package Standard is type Universal_Array is abstract; -- The base type of all arrays type Universal_Array'Index is abstract; -- Defines anonymous type and abstract type -- attribute 'Index to override type Universal_Array'Element is abstract; function "()" ( Container : Universal_Array; Index : Universal_Array'Index ) return Universal_Array'Element is abstract; When you inherit from (implement) an abstract array type, you have to implement all abstract operations it has. The most difficult problem, when one wishes to get rid of generics (*), is to bring together three types: array, index, element. One could define abstract array of abstract constrained elements over abstract index. But then when you derive from it, you have also derive from index and element. This is a known problem of handling parallel type hierarchies. It appears quite often and seems need to be solved anyway. (*) Surely one could further pursue the present Ada approach to arrays, which is kind of hard-wired "template", because "type X is array (Y) of Z", is much close to a generic instantiation. The problem with that is, that anything that should work with different array types automatically becomes generic as well, which ends in STL for Ada. If we could lift this limitation, things might become much easier. > Is this efficient? How many checks are needed at run time (in the > presence of separate compilation)? Implementations can be declared inline. It does not differ from templates. Then I'd like to have a mechanism to fore compile-time evaluation of pure functions, when arguments are static. This would solve all problems with efficiency. More difficult problems are: 1. setters 2. anonymous array subtypes and anonymous subarray types needed to all sorts of aggregates and slices 3. user-defined aggregates, of course 4. same with index types, to have ranges > How do you get hold of plain basic types? I see no problem with them. For example, discrete types could be considered derived from some abstract index type. So type I is range 1..40; be treated as an abbreviation of something like: type I is new Ordered_Index with range 1..40; -- function ">" (Left, Right : I) return Boolean implements -- function ">" (Left, Right : Ordered_Index) return Boolean is abstract; etc -- Regards, Dmitry A. Kazakov www.dmitry-kazakov.de