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: Sun, 23 May 2004 10:55:56 +0200
Date: 2004-05-23T10:55:56+02:00	[thread overview]
Message-ID: <2hb77mFabusrU1@uni-berlin.de> (raw)
In-Reply-To: c8mkor$rlq$1@a1-hrz.uni-duisburg.de

Georg Bauhaus wrote:

> Dmitry A. Kazakov <mailbox@dmitry-kazakov.de> wrote:
>  
> : (*) 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.
> 
> Easier in which way? It is very easy to write a multimethod in CLOS.
> I think it is also very easy to forget a whole bunch of cases,
> each part of the parameter profile multiplying the number of cases.

Are you talking about MD? If Ada should support it, then there RM should
require that when one signature of a primitive operation gets overridden
all other signatures of the operation should be explicitly overridden as
well. To reduce the number of cases one should also provide language
support for commutative operations and ones in parallel type hierarchies.

> It also incurs some mechanism that dedices what to call based on
> arguments, right?

That's no problem. The type tag could be an index in a multidimensional
dispatch table.

> Likewise, how does it become easier to write all the implementations?

Discrete types are predefined. Implementations will be needed in non-trivial
cases only. For example, if you want an array indexed by String.

> If everything that some construct like abstract array indexing needs
> has to be provided by the implmenting types, this might easily lead
> to type inflation.

How it differs from what we have now:

generic
   type Index is private;
   with function ">" (Left, Right : Index) return Boolean;
   with function First return Index;
   ...

You have to implement ">" before you instantiate.

> I'm not sure whether or not this is better than to
> define operations based on what the type already has, and near where
> they are needed.

You will have this for free with multiple inheritance. Consider a possible
scenario of making Integer an array index. It is made by deriving a new
type from Integer (by implementation inheritance) and abstract index type
(by interface inheritance). The inherited Integer implementation will
implement the index interface. This is what will happen behind the scene
when you write "array (Integer range <>) of".

> :> Is this efficient? How many checks are needed at run time (in the
> :> presence of separate compilation)?
> : 
> : Implementations can be declared inline.
> 
> But won't implementations have to have some overhead, inlined or not?
>
> Say you make Number a base class for all sorts of numbers.

That will be an abstract type with no implementation, just an interface. As
such it is just a label you can attach to any type by providing
implementations.

> How do you manage to write code so the compiler will know
> it deals with numbers of the kind required in some algorithm
> involving Array or MultiArray without whole program analysis?

You cannot have objects of an abstract type (interface). So what you would
do to write a program dealing with all kind of numbers? Presently it is
impossible, so there is nothing to compare with.

I have an idea of ad-hoc supertypes. Instead of making all numbers derived
from Number, sharing its implementation, which will be either impossible or
inefficient, we could create such supertypes as necessary *afterwards*. So
if you want to bring Integer and Float under one roof, you create a common
non-abstract supertype MyNumber. This would require an implementation for
MyNumber, which can be made more efficient, because you know all the
players. Observe that now you have a choice:

1. either you write your numeric library in terms of MyNumber, which would
make it possible to have efficient shared bodies.

2. or you write it in terms of Number'Class, which will be less efficient if
bodies are not inlined (the compiler does not know ultimate type
representation).

> : It does not differ from templates.
> 
> If you pass pairs of pointers around, and have separate compilation,
> and specs and bodies, and access types with values pointing to some
> derivation, I imagine a multimethod like
> 
>    function "()"(mine: Basket; i: JumpyIndex) return Goods;
> 
> will still not be that quick, unless everything about it can be
> found out at compile time. Is this correct?

With multimethod (=MD), "()" will dispatch. That's the only overhead I see,
and only if the destination is not statically known. Parameter passing
mechanism can be any.

> : 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.
> 
> All problems?

Many. You will have unbounded strings, statically checkable dimensioned
values, all user-defined! to begin with...

> How much is static in an average program?

This varies depending on the application field. In an embedded system it
could be 100%.

The goal is to go static as much as possible, but also to have an ability to
switch to dynamic (=less efficient) approach when you cannot otherwise.

> How long does program analysis take for the compiler to find out?
> Or is it the linker?

I do not expect any new problems here. I presume that generics/templates
impose the most difficult problems for compilers (and programmers too).
Dymanic management of dispatching tables could become a problem if we relax 
restrictions of the contexts where the new types can be derived.

> : 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.
> 
> Hmmnn, if the compiler knows about some very special derivations
> it might know how to use processor registerers for indexing.
> Otherwise....
> 
> : 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;
> 
> This looks somewhat like Haskell, doesn't it?

I cannot judge.

-- 
Regards,
Dmitry A. Kazakov
www.dmitry-kazakov.de



  parent reply	other threads:[~2004-05-23  8:55 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
     [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 [this message]
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