comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: "Must instantiate controlled types at library level." Why?
Date: Fri, 21 May 2004 22:33:24 +0200
Date: 2004-05-21T22:33:24+02:00	[thread overview]
Message-ID: <2h77beF9tvamU1@uni-berlin.de> (raw)
In-Reply-To: c8kpot$r49$1@a1-hrz.uni-duisburg.de

Georg Bauhaus wrote:

> Dmitry A. Kazakov <mailbox@dmitry-kazakov.de> 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



  reply	other threads:[~2004-05-21 20:33 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-11 23:04 "Must instantiate controlled types at library level." Why? Peter C. Chapin
2004-05-12  1:03 ` Jeffrey Carter
2004-05-12 10:47   ` Peter C. Chapin
2004-05-12 11:25     ` Ludovic Brenta
2004-05-12 14:41       ` Martin Krischik
2004-05-13  2:20       ` Peter C. Chapin
2004-05-12 11:55     ` Martin Krischik
2004-05-13  2:59       ` Peter C. Chapin
2004-05-13  7:10         ` Martin Krischik
2004-05-13 10:36           ` Peter C. Chapin
2004-05-13 11:18             ` Martin Krischik
2004-05-13 22:27               ` Peter C. Chapin
2004-05-13 22:54               ` Freejack
2004-05-14  7:13                 ` Martin Krischik
2004-05-14 13:50                   ` Xenos
2004-05-14 17:27                     ` Georg Bauhaus
2004-05-14 17:58                       ` Xenos
2004-05-14 18:49                     ` Martin Krischik
2004-05-14 19:40                       ` Xenos
2004-05-14 22:47                         ` Ludovic Brenta
2004-05-15  8:34                           ` Martin Krischik
2004-05-16  2:55                           ` Hyman Rosen
2004-05-16 13:48                             ` Ludovic Brenta
2004-05-17  2:30                               ` Hyman Rosen
2004-05-17  5:39                                 ` Martin Dowie
2004-05-17  7:48                                   ` Ludovic Brenta
2004-05-17 15:01                                     ` Hyman Rosen
2004-05-17 16:31                                       ` Georg Bauhaus
2004-05-17 17:40                                         ` Hyman Rosen
2004-05-17 19:17                                           ` Georg Bauhaus
2004-05-17  6:24                                 ` Martin Krischik
2004-05-17 19:48                                   ` James Kanze
2004-05-18  6:27                                     ` Martin Krischik
2004-05-17 12:33                                 ` Dmitry A. Kazakov
2004-05-17 13:46                                   ` Martin Krischik
2004-05-17 15:03                                     ` Dmitry A. Kazakov
2004-05-17 16:02                                   ` Alexander E. Kopilovich
2004-05-18  7:48                                     ` Dmitry A. Kazakov
2004-05-19  1:20                                       ` Alexander E. Kopilovich
2004-05-19  9:59                                         ` Dmitry A. Kazakov
2004-05-19 12:38                                           ` Hyman Rosen
2004-05-19 13:28                                             ` Dmitry A. Kazakov
2004-05-19 13:09                                           ` Georg Bauhaus
2004-05-19 13:44                                             ` Hyman Rosen
2004-05-19 14:17                                               ` Dmitry A. Kazakov
2004-05-19 14:15                                             ` Dmitry A. Kazakov
2004-05-21 11:39                                               ` Georg Bauhaus
2004-05-21 20:33                                                 ` Dmitry A. Kazakov [this message]
     [not found]                                                   ` <c8mkor$rlq$1@a1-hrz.uni-duisburg.de>
2004-05-23  1:28                                                     ` Hyman Rosen
2004-05-23  8:55                                                     ` Dmitry A. Kazakov
2004-05-24 11:38                                                       ` Georg Bauhaus
2004-05-24 13:57                                                         ` Dmitry A. Kazakov
2004-05-24 14:40                                                           ` Georg Bauhaus
2004-05-25  8:32                                                             ` Dmitry A. Kazakov
2004-05-25 15:47                                                               ` Georg Bauhaus
     [not found]                                   ` <URJ8Eg0vzF@VB1162.spb.edu>
2004-05-17 16:50                                     ` Marius Amado Alves
2004-05-18  8:27                                       ` Dmitry A. Kazakov
2004-05-15 17:20                     ` Pascal Obry
2004-05-13 19:33             ` 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