comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: User-defined type attributes (replacing genericity)
Date: Fri, 14 Mar 2008 19:39:57 +0100
Date: 2008-03-14T19:39:57+01:00	[thread overview]
Message-ID: <84a4svy5kv3b.1o9ncie8w50qi$.dlg@40tude.net> (raw)
In-Reply-To: 1205513926.7434.3.camel@K72

On Fri, 14 Mar 2008 17:58:46 +0100, Georg Bauhaus wrote:

> On Fri, 2008-03-14 at 15:48 +0100, Dmitry A. Kazakov wrote:
> 
>>> I assume your answer to what follows will be that Ada semantics
>>> should be put under programmer control,
>> 
>> What's wrong with having control over the semantics?
> 
> (Control over the semantics of the language. I'm not a compiler,
> and I'm not imagining I am as good as someone who can routinely
> master the advanced parts of implementing Ada in user programs.
> That is what I think will be wrong.

But the compiler is in an even worse position. It cannot know your intent
when you introduce a new operation, type, object etc. It is up to you to
define the semantics of.

> It is certainly possible to imagine some meta-flavoring for
> Ada. But I don't want to inspect such pieces of sophistication
> when they come out of the hands of ordinary programmers
> and have errors. There will be at least one more
> level of linguistic indirection between me and the LRM:
> the programmer's language interpretation as implemented in
> his semantics control.)

Sorry, but it is generics which constitute a meta language, so this
argument you should address to yourself.

Further, it seems that you believe that Ada defines some meta-level
semantics of attributes and operations like "+", "-", etc. But, it does
not. You can define "+" to perform multiplication or to act on tasks.

BUT, if you wanted to do that (I don't), then again the first step should
be away from generics, towards proper classes. For example, to define a
class of additive objects and to forbid use of "+" for anything outside the
class.

>> No, what you need is an interface implemented by both. You need to declare
>> Simple implementing Ordered. That will tell the compiler that the
>> predefined "<=" is an implementation of Ordered's "<=".
> 
> Actually, it doesn't matter whether "<=" is predefined. It could
> just as well have been a user defined "<=". The Foo(...'Class) would
> have had one one general ("generic"?) implementation of Is_Highest,
> as described. This Is_Highest will have no specialization, but
> it will feature highly stylized indirection, dispatching to the
> implementing code for the respective "<=".

In fact, your code will not compile. It should be:

   function Is_Highest (V: T'Class) return Boolean is
   begin
      return X <= V and then Y <= V and then Z <= V;
   end Is_Highest;

So what was the problem?

>>> Without generics, there is only one Is_Highest, as might be
>>> expected. 
>> 
>> Why there have to be two? The whole idea of generics was to have *one*
>> generic body. This is why it is called generic [programming].
> 
> I *can* have and I *did* have just one body in *source* code.

Yes this is what I meant.

> We both know that Ada does not anywhere require that generics
> must not yield more than one lists of object code per
> generic. This would seem like a stupid restriction, one that
> I think no one has wanted to put in the minds of the language
> makers.

I didn't meant the implementation. Semantically there is one body even if
instantiations expand it.

>> If you want to constrain the dispatching table to the diagonal
> 
> I don't want that language to inflict a dispatching table
> on me when that offers no advantage at all!

Dispatching table is not a physical object. It is a formal model to
describe operations defined on a class. Such polymorphic operations have
type-specific implementations (because the language is strongly typed). The
dispatching table lists them according to the order relation (subtyping) of
the types of the arguments. How and if to implement it is up to the
compiler.

> - I don't need any dispatching here,

You have to. Dispatch is a selection of a type-specific body responsible
for the implementation of a generic (polymorphic) one for the given
combination of argument types. When you instantiate a generic body it is an
act of dispatching, performed manually.

> - My code is more efficient without it,

It is not Ada's objective. Then with statically known types and inlined
bodies you could have the same code GNAT generics produce.

> - Review of the generated code is simpler because
>   there are fewer indirections.

I never review generated code. I wrote large (then) programs about 20K
SLOC, now I am using Ada, I don't want back.

> - There still is abstraction.

Where? In the object code?

>>  Do not sell a limitation of generics to a
>> certain type of constraint as genuine advantage.
> 
> From looking at generated code, the genuine advantage seems
> to be the total absence of dispatching code.

You don't need any code when dispatch is static.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2008-03-14 18:39 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-12 18:58 User-defined type attributes Eric Hughes
2008-03-12 21:23 ` Dmitry A. Kazakov
2008-03-13 18:32   ` Eric Hughes
2008-03-13 19:58     ` Dmitry A. Kazakov
2008-03-14  1:46       ` Randy Brukardt
2008-03-14  9:00         ` Dmitry A. Kazakov
2008-03-14 14:36           ` User-defined type attributes (replacing genericity) Georg Bauhaus
2008-03-15  3:04           ` User-defined type attributes Randy Brukardt
2008-03-15  9:33             ` Dmitry A. Kazakov
2008-03-14 14:31         ` User-defined type attributes (replacing genericity) Georg Bauhaus
2008-03-14 14:48           ` Dmitry A. Kazakov
2008-03-14 17:51             ` Eric Hughes
2008-03-14 18:58               ` Dmitry A. Kazakov
2008-03-14 20:19                 ` Eric Hughes
2008-03-15  4:01               ` Randy Brukardt
2008-03-14 16:58           ` Georg Bauhaus
2008-03-14 18:39             ` Dmitry A. Kazakov [this message]
2008-03-15  9:39               ` Dmitry A. Kazakov
2008-03-14  1:46       ` User-defined type attributes Randy Brukardt
2008-03-14  1:46       ` Randy Brukardt
2008-03-14  3:55       ` Eric Hughes
2008-03-14  9:01         ` Dmitry A. Kazakov
2008-03-14 18:04           ` Eric Hughes
2008-03-14  1:46 ` Randy Brukardt
2008-03-14  4:41   ` Eric Hughes
2008-03-15  3:20     ` Randy Brukardt
2008-03-17  4:38       ` Eric Hughes
2008-03-17 21:03         ` Randy Brukardt
2008-03-17 21:58           ` Eric Hughes
replies disabled

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