comp.lang.ada
 help / color / mirror / Atom feed
From: Dmitry A. Kazakov <mailbox@dmitry-kazakov.de>
Subject: Re: Imitation is the sincerest form of flattery
Date: Fri, 28 Mar 2003 14:34:05 +0100
Date: 2003-03-28T14:34:05+01:00	[thread overview]
Message-ID: <ekh88vos6htuolmqn316g53ce4jrs09e3i@4ax.com> (raw)
In-Reply-To: GxIga.15773$hB5.8010@nwrdny02.gnilink.net

On Thu, 27 Mar 2003 19:45:42 GMT, "Frank J. Lhota"
<NOSPAM.lhota.adarose@verizon.net> wrote:

>"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
>news:b5qcnq$2bshmf$1@ID-77047.news.dfncis.de...
>> Frank J. Lhota wrote:
>>
>> > I wish that we had the following functions defined in the Standard
>> > package:
>> >
>> >     function Pred( X : Integer ) return Integer;
>> >     function Max( X, Y : Integer ) return Integer;
>> >     -- etc.
>> >
>> > This would allow the programmer to re-define any of these attributes for
>> > types derived from Integer (or other predefined types).
>>
>> True, but it is a very long way to go. For example, to have 'Max
>> dispatching, you would immediately need true multiple dispatch - it has
>two
>> parameters!
>
>AFAIK (and my testing seems to confirm this) if we have the function
>
>     function Max( X, Y : An_Integer_Type ) return An_Integer_Type;
>
>defined in the same package as An_Integer_Type, and if we derive a type
>New_Integer from An_Integer_Type, i.e.
>
>    type New_Integer is new An_Integer_Type;
>
>then New_Integer inherits Max from An_Integer_Type, i.e. there is an
>implicit function
>
>     function Max( X, Y : New_Integer ) return New_Integer;
>
>that the programmer can either call or replace with his own version.

This is absolutely another story. type A is new B, "clones" types. The
result is a new type which is same as B. From this point of view Max
is not inherited by New_Integer. Consider:

X : Integer;
Y : New_Integer;

Max (X, Y); -- Illegal!

Should Max be inherited Max (X, Y) would be legal.

BTW it is pitty that type cloning is not allowed for tagged types. IMO
this restriction should be removed.

>Multiple dispatching would only be an issue if we wanted to generate a
>version of Max that compares and / or returns different integer types. By
>the very nature of the Max function, we are unlikely to even want to do
>that.

My point is *IF*:

1. Inheritance has to be supported for all types in the sense that
Integer'Class might refer to descendants of Integer

2. The attributes has to be declared as primitive operations

Then you have to support MD for all attributes with several arguments.

So 'Max would be declared as:

   function 'Max (Left, Right : Integer) return Integer'Class;


There is no other choice. The present situation when tags of both
arguments has to be same is unsatisfactory. It is not so bad now,
because the tagged types are too heavy (passed by reference, have
embedded tag) to use them for representation of numeric things. There
binary operations are very common. Should you make OO available there,
this will become a problem:

   function 'Max (Left : Integer; Right : Integer'Class)
      return Integer'Class;

+ manual dispatch on Right is awful!

>This is not to dismiss the utility of multiple dispatching, but
>unfortunately most OOPL's avoid it because of efficiency concerns.

There are many problems with MD, but I do not think that efficiency is
a big issue. It will probably cost one indirection more.

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



  parent reply	other threads:[~2003-03-28 13:34 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-14 17:22 Imitation is the sincerest form of flattery Robert C. Leif
2003-03-14 17:57 ` Warren W. Gay VE3WWG
2003-03-14 18:16 ` chris.danx
2003-03-14 18:17 ` Hyman Rosen
2003-03-15 14:18   ` Georg Bauhaus
2003-03-16  1:06     ` Hyman Rosen
2003-03-18 10:37       ` Georg Bauhaus
2003-03-18 15:34         ` Dmitry A. Kazakov
2003-03-19 11:12           ` Georg Bauhaus
2003-03-20  8:42             ` Dmitry A. Kazakov
2003-03-20 14:27               ` Frank J. Lhota
2003-03-21  8:44                 ` Dmitry A. Kazakov
2003-03-21 17:16                   ` Pascal Obry
2003-03-22  9:05                     ` Dmitry A. Kazakov
2003-03-22 14:11                       ` Pascal Obry
2003-03-22 23:12                         ` AG
2003-03-23  9:01                           ` Dmitry A. Kazakov
2003-03-23  8:51                         ` Dmitry A. Kazakov
2003-03-24 16:52                           ` Hyman Rosen
2003-03-24 18:10                             ` Dmitry A. Kazakov
2003-03-24 18:33                               ` Hyman Rosen
2003-03-25  5:04                                 ` Amir Yantimirov
2003-03-25 19:55                                 ` Dmitry A. Kazakov
2003-03-25 20:22                                   ` Hyman Rosen
2003-03-26 13:02                                     ` Dmitry A. Kazakov
2003-03-26 15:06                                       ` Hyman Rosen
2003-03-26 16:21                                         ` Dmitry A. Kazakov
2003-03-26 17:00                                           ` Hyman Rosen
2003-03-26 18:21                                             ` Bill Findlay
2003-03-26 18:40                                               ` Hyman Rosen
2003-03-22 10:01                   ` Amir Yantimirov
2003-03-23  8:41                     ` Dmitry A. Kazakov
2003-03-24  4:53                       ` Amir Yantimirov
2003-03-24 18:10                         ` Dmitry A. Kazakov
2003-03-25  5:48                           ` Amir Yantimirov
2003-03-25 15:53                             ` Frank J. Lhota
2003-03-25 16:44                               ` Robert A Duff
2003-03-25 18:24                                 ` Frank J. Lhota
2003-03-25 20:06                                   ` Dmitry A. Kazakov
2003-03-27 19:45                                     ` Frank J. Lhota
2003-03-27 21:25                                       ` Pascal Obry
2003-03-28 13:34                                       ` Dmitry A. Kazakov [this message]
2003-04-01 14:38                                         ` Frank J. Lhota
2003-04-02  7:37                                           ` Dmitry A. Kazakov
2003-03-26  7:48                                 ` Amir Yantimirov
2003-03-26 13:35                                   ` Dmitry A. Kazakov
2003-03-26  7:32                               ` Amir Yantimirov
2003-03-20 23:28               ` Matthew Heaney
2003-03-21  8:49                 ` Dmitry A. Kazakov
2003-03-21 21:07                   ` Georg Bauhaus
2003-03-22  9:04                     ` Dmitry A. Kazakov
2003-03-22 10:05                       ` AG
2003-03-22 15:25                         ` Georg Bauhaus
2003-03-22 19:27                           ` AG
2003-03-22 21:45                             ` Vinzent Hoefler
2003-03-22 22:28                               ` AG
2003-03-23 23:47                     ` Robert A Duff
2003-03-28 16:34                       ` Georg Bauhaus
2003-03-18 15:58         ` Hyman Rosen
2003-03-19 11:05           ` Georg Bauhaus
2003-03-23 11:31       ` Florian Weimer
2003-03-23 23:39         ` Hyman Rosen
2003-03-15 12:52 ` Florian Weimer
replies disabled

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