comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Operation can be dispatching in only one type
Date: Mon, 16 Nov 2009 23:28:32 +0100
Date: 2009-11-16T23:28:32+01:00	[thread overview]
Message-ID: <39kf90ha60px$.d7746cf5cx6h.dlg@40tude.net> (raw)
In-Reply-To: adaa8b66-1394-45f9-a822-48f0bfb5c2cb@u16g2000pru.googlegroups.com

On Mon, 16 Nov 2009 13:35:00 -0800 (PST), Adam Beneschan wrote:

> On Nov 16, 12:28�pm, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
>> On Mon, 16 Nov 2009 09:43:06 -0800 (PST), Adam Beneschan wrote:
>>> By the way, for a while I was considering requesting a language change
>>> to allow this sort of restricted multiple dispatch, in cases where a
>>> primitive operation of two types could be declared and inherited for
>>> two derived types that are derived in the same package, and when
>>> dispatching, the program would check to make sure the two actual types
>>> really were declared in the same package. �This would avoid having to
>>> deal with M x N combinations of types---something that I think is an
>>> issue with MI---since it only deals with pairs (or triplets, etc.) of
>>> types that are defined to "go together".
>>
>> But you still have these combinations independently on where you derive.
>> You allow the "diagonal" of the full dispatching table. I.e. the
>> combinations:
>>
>> A1, B1,
>> A2, B2,
>> A3, B3
>>
>> But other combinations are still there, because they can be spelt. It is
>> just so that they raise Constraint_Error. This "diagonal" behavior is what
>> we already have for multi-methods (a form of MD with only one hierarchy
>> A=B). I suppose this is one of the motivations of your proposal.
>>
>> But the problem with "diagonal" dispatch is that it is inconsistent with
>> the idea of static typing. I would insist on the design rule that dispatch
>> shall never fail in a legal program. I.e. the compiler shall enforce all
>> possible combinations of types no later than at compile time.
> 
> Since a call to a dispatching operation may have parameters that are
> themselves of class-wide types, I don't think this is possible.

No, what I have in mind is that each time a new type is derived, we could
somehow ensure that the whole row M+1 (from N x M+1) is filled either by a
overriding or per a reasonable inheritance. The major problem is that we
cannot see all Ns when we do M+1.

The idea of deriving both types in one package looks like an attempt to
control the places where we can expand the table N x M. That is not enough
to enforce completeness of the table in the above sense.

There should be something more strong, but also more liberal in terms of
modularization. Obviously to derive from all types related via a shared
primitive operation in one package is awful (and sometimes just impossible
within the given parent-child hierarchy of packages).

> In Ada as it exists currently, you can declare a primitive operation
> with two parameters of the same tagged type (maybe that's what you
> meant by "multi-method"---sorry, I don't know the jargon).  E.g.
> 
>    type T is abstract tagged null record;
>    procedure Some_Operation (Param_1 : T; Param_2 : T);
> 
> If you later call
> 
>    Some_Operation (X, Y);
> 
> and X is declared to be of type T1 (a descendant of T) and Y is
> declared to be of type T2 (also a descendant of T), then the compiler
> can statically determine that this will fail.  But if either X or Y
> (or both) is declared to be of type T'Class, then the compiler can't
> statically tell whether the dispatch will fail or not.  So a runtime
> check is needed.  Similarly for the proposal I was thinking of making.

Yep, this is what I meant. The compiler should require to override *all*
combinations:

   type T2 is new T1 with ...;
   overriding
      procedure Some_Operation (X : T2; Y : T2);
        -- Error!

   overriding
      procedure Some_Operation (X : T2; Y : T2);
   overriding
      procedure Some_Operation (X : T1; Y : T2);
   overriding
      procedure Some_Operation (X : T2; Y : T1);
         -- OK

Yes, this is tedious, but the programmer should know what we does when he
declares a multi-method. This is the semantics of - there are n**2
combinations which do potentially different things. If there are only n
combinations, that is another case, which should *not* look MD, because it
is not. I think it should somehow use tuples instead. The error should
happen upon tuple construction, not in the call. For the reader it should
be clear that there is only one tag. I have no idea how to spell that
syntactically or by other means.

Al for "true" multi-methods I think we should support delegation in order
to control combinatorial explosion. For example:

1. declaration Some_Operation commutative;

2. explicit delegation of T2 x T1 to T1 x T2

   overriding
      procedure Some_Operation (X : T2; Y : T1)
         renames Some_Operation with (X => Y, Y => X);

3. delegation of T1 x T2 to T2 x T2 supplying a downcast conversion from T1
to T2

   overriding
      procedure Some_Operation (X : T1; Y : T2)
         renames Some_Operation with (X => (X with ...), Y => Y);

4. delegation of T2 x T2 to T1 x T2 (upcast)

   overriding
      procedure Some_Operation (X : T2; Y : T2)
         renames Some_Operation with (X => T1 (X), Y => Y);

etc.

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



  reply	other threads:[~2009-11-16 22:28 UTC|newest]

Thread overview: 132+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-13 20:12 Operation can be dispatching in only one type xorque
2009-11-13 20:34 ` Dmitry A. Kazakov
2009-11-13 20:43   ` xorque
2009-11-13 21:14     ` Dmitry A. Kazakov
2009-11-13 20:44   ` xorque
2009-11-16 17:43 ` Adam Beneschan
2009-11-16 20:28   ` Dmitry A. Kazakov
2009-11-16 20:32     ` Dmitry A. Kazakov
2009-11-16 21:35     ` Adam Beneschan
2009-11-16 22:28       ` Dmitry A. Kazakov [this message]
2009-11-17 22:10         ` Adam Beneschan
2009-11-18  9:46           ` Dmitry A. Kazakov
2009-11-18 16:39             ` Adam Beneschan
2009-11-18 19:21               ` Dmitry A. Kazakov
2009-11-19  0:27                 ` Randy Brukardt
2009-11-19  2:11                   ` Robert A Duff
2009-11-19 15:57                     ` Adam Beneschan
2009-11-19 19:39                       ` Robert A Duff
2009-11-19 23:43                         ` Randy Brukardt
2009-11-19  8:50                   ` Dmitry A. Kazakov
2009-11-19 23:54                     ` Randy Brukardt
2009-11-20  8:34                       ` Dmitry A. Kazakov
2009-11-20 10:58                         ` Jean-Pierre Rosen
2009-11-21  6:02                         ` Randy Brukardt
2009-11-21 13:07                           ` Dmitry A. Kazakov
2009-11-22  5:45                         ` xorque
2009-11-22 11:25                           ` Georg Bauhaus
2009-11-22 11:30                             ` xorque
2009-11-22 16:25                             ` Dmitry A. Kazakov
2009-11-22 16:27                               ` xorque
2009-11-22 16:42                                 ` Dmitry A. Kazakov
2009-11-22 16:52                                   ` xorque
2009-11-22 17:41                                     ` Dmitry A. Kazakov
2009-11-22 18:03                                       ` xorque
2009-11-22 18:08                                         ` xorque
2009-11-22 18:28                                         ` Dmitry A. Kazakov
2009-11-22 18:41                                           ` xorque
2009-11-22 21:47                                           ` Robert A Duff
2009-11-23  3:42                                             ` stefan-lucks
2009-11-30 20:36                                               ` Robert A Duff
2009-11-30 23:54                                                 ` (see below)
2009-12-01 12:13                                                 ` Georg Bauhaus
2009-12-01 12:23                                                   ` Georg Bauhaus
2009-12-01 12:44                                                     ` Georg Bauhaus
2009-12-01 13:48                                                   ` Dmitry A. Kazakov
2009-12-01 15:02                                                     ` Georg Bauhaus
2009-12-01 16:18                                                       ` Dmitry A. Kazakov
2009-12-01 17:52                                                         ` Georg Bauhaus
2009-12-01 18:47                                                           ` Dmitry A. Kazakov
2009-12-01 21:53                                                             ` John B. Matthews
2009-12-02  0:32                                                               ` Georg Bauhaus
2009-12-02 11:18                                                                 ` John B. Matthews
2009-12-02 14:29                                                                   ` Jean-Pierre Rosen
2009-12-02 15:35                                                                     ` Georg Bauhaus
2009-12-02  1:13                                                             ` Georg Bauhaus
2009-12-02  9:07                                                               ` Dmitry A. Kazakov
2009-12-02 12:35                                                                 ` John B. Matthews
2009-12-02 13:35                                                                   ` Dmitry A. Kazakov
2009-12-03  5:23                                                                   ` Randy Brukardt
2009-12-03 20:21                                                                     ` John B. Matthews
2009-12-03  5:29                                                                 ` Randy Brukardt
2009-12-03 11:24                                                                   ` Georg Bauhaus
2009-12-03 23:08                                                                     ` Randy Brukardt
2009-12-04  8:52                                                                       ` Dmitry A. Kazakov
2009-12-05  2:45                                                                         ` Randy Brukardt
2009-12-05 10:32                                                                           ` Dmitry A. Kazakov
2009-12-08  0:19                                                                             ` Randy Brukardt
2009-12-08  4:30                                                                               ` stefan-lucks
2009-12-08  9:12                                                                                 ` Dmitry A. Kazakov
2009-12-10  4:09                                                                                   ` Randy Brukardt
2009-12-11  0:10                                                                                 ` Robert A Duff
2009-12-08  9:22                                                                               ` Dmitry A. Kazakov
2009-12-08 10:06                                                                                 ` Georg Bauhaus
2009-12-08 10:23                                                                                   ` Dmitry A. Kazakov
2009-12-08 10:33                                                                                     ` Georg Bauhaus
2009-12-08 10:49                                                                                       ` Dmitry A. Kazakov
2009-12-01 23:51                                                   ` Randy Brukardt
2009-11-23  8:52                                             ` Dmitry A. Kazakov
2009-11-30 20:43                                               ` Robert A Duff
2009-12-01  9:00                                                 ` Dmitry A. Kazakov
2009-12-01  5:45                                                   ` stefan-lucks
2009-12-01 11:12                                                     ` Dmitry A. Kazakov
2009-12-01  8:01                                                       ` stefan-lucks
2009-12-01 13:37                                                         ` Dmitry A. Kazakov
2009-12-15 23:54                                                         ` Robert A Duff
2009-11-23  7:48                                         ` Georg Bauhaus
2009-11-23  7:58                                           ` Georg Bauhaus
2009-11-19 16:04                 ` Adam Beneschan
2009-11-19  2:23           ` tmoran
2009-11-19  8:32             ` Dmitry A. Kazakov
  -- strict thread matches above, loose matches on Subject: below --
2015-11-23 10:23 operation " Serge Robyns
2015-11-23 11:29 ` Dmitry A. Kazakov
2015-11-23 13:05   ` Serge Robyns
2015-11-23 13:48     ` Dmitry A. Kazakov
2015-11-23 14:16       ` Serge Robyns
2015-11-23 14:59         ` G.B.
2015-11-23 15:52         ` Dmitry A. Kazakov
2015-11-23 17:40 ` Jeffrey R. Carter
2015-11-24  9:08   ` Serge Robyns
2015-11-24 16:44     ` AdaMagica
2015-11-24 17:09     ` Jeffrey R. Carter
2015-11-24 18:37       ` Serge Robyns
2015-11-24 20:18         ` Jeffrey R. Carter
2015-11-24 20:40           ` Serge Robyns
2015-11-24 20:25       ` Niklas Holsti
2015-11-24 21:48         ` Jeffrey R. Carter
2015-11-25  8:24           ` Dmitry A. Kazakov
2015-11-25 11:22             ` Serge Robyns
2015-11-25 17:38               ` Dmitry A. Kazakov
2015-11-26 11:30                 ` Serge Robyns
2015-11-26 13:14                   ` Dmitry A. Kazakov
2015-11-26 14:27                     ` Serge Robyns
2015-11-26 15:16                       ` J-P. Rosen
2015-11-26 18:27                         ` Serge Robyns
2015-11-26 21:20                           ` J-P. Rosen
2015-11-27  8:37                             ` Dmitry A. Kazakov
2015-11-27 12:58                               ` J-P. Rosen
2015-11-27 13:39                                 ` Dmitry A. Kazakov
2015-11-30 22:22                                   ` Randy Brukardt
2015-12-01  8:46                                     ` Dmitry A. Kazakov
2015-12-01 11:19                                       ` G.B.
2015-12-01 13:56                                         ` Dmitry A. Kazakov
2015-12-01 16:05                                           ` G.B.
2015-12-01 17:58                                             ` Dmitry A. Kazakov
2015-12-02 13:06                                               ` G.B.
2015-12-02 13:31                                                 ` Dmitry A. Kazakov
2015-12-02 19:33                                           ` Randy Brukardt
2015-12-02 19:27                                       ` Randy Brukardt
2015-11-29 17:59                     ` Jacob Sparre Andersen
2015-11-30 22:29                       ` Randy Brukardt
2015-11-25 12:27             ` G.B.
2015-11-25 17:25               ` Dmitry A. Kazakov
replies disabled

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