comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Ada Interfaces and the Liskov Substitution Principle
Date: Sun, 27 May 2007 12:04:21 +0200
Date: 2007-05-27T12:04:12+02:00	[thread overview]
Message-ID: <1p717twnydnre$.1j6izygvqo832.dlg@40tude.net> (raw)
In-Reply-To: 1180254636.632499.3340@o5g2000hsb.googlegroups.com

On 27 May 2007 01:30:36 -0700, Maciej Sobczak wrote:

> On 26 Maj, 09:48, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
> 
>>> I'm still for banning it.
>>
>> For this you have to make assignment contravariant (non-primitive
>> operation) in one of its arguments. That would be a total mess, because it
>> would require overloading assignment for each derived type.
> 
> I don't get it. I said I would ban it. There is no "for this". :-)

To ban something in the language you have to translate the ban into
language terms. That could be either by syntax or by semantic rules.
Because syntactically banned assignments are indistinguishable from legal
ones, the only mechanics you could use for this is matching types. The
types in question are from the same hierarchy (covariant). This lets mixing
such types. So it *must* be contravariant to be banned = the operation
(":=") will not be inherited in the argument of interest upon inheritance.

>> For the same reason all signatures with a class-wide parameter are bad,
>> because they lead to ambiguities in trivial cases:
>>
>> type S is new T with ...;
>> X, Y : S;
>>
>> X := Y;  -- S'Class x S'Class vs T'Class x T'Class?
>>
>> You will need some sort of dominance rules to resolve that.
> 
> Why?

Per definition/meaning of class-wide operations: they apply to *all* types
from the class.

> Both X and Y are of the same type above and it is not a class
> wide type in the sense that no dispatching is needed here.

Dispatching is about primitive operations acting on class-wide objects.
Class-wide operations acting on specific objects is a way different story.

>> P.S. Probably you have in mind a "stratified" assignment which statically
>> checks that LHS and RHS are of the same type.
> 
> Not necessarily. I would allow different types if the
> assignment_statement is overloaded for them for those who like to
> introduce sort of implicit conversions.
> What I worry about is the situation where *both* dynamic types are not
> known statically. This is a mess.

You cannot express it in terms of the types system. So you have to roll up
another formal types framework.

And I don't see why it is a mess. What is wrong in assignment of
UTF8_String to Wide_String, both from String'Class?

The very definition of a class says that types there share class-wide and
primitive operations. If that is not the case: ":=" is not shared, then
either it is not a class (= don't derive! if need not) or there is no ":="
(= make it limited! if unsure). Looks much like a design problem.

>> -----------
>> *  Ada's assignment is doubly dispatching. The dispatching table is a
>> square, the diagonal of consists of thunks:
>>
>>    Finalize (LHS);
>>    bit-copy (LHS, RHS);
>>    Adjust (LHS);
>>
>> Non-diagonal elements are:
>>
>>    raise Constraint_Error;
> 
> Which is a run-time thingy. It's good if it's there, but I want
> stricter guarantees. You can get them by just banning
> assignment_statement between class-wide types.

No, because that would be inconsistent. A doubly dispatching operation
*has* a square table. There is nothing to do about it. You have to make it
something else instead, I have listed possible variants earlier. These
alternatives are mess. Hardwired rules imposed on assignments were an even
bigger mess. It is bad enough that Ada has assignment defined as an
statement, rather than a procedure call. There is nothing special in
assignments. So your mechanism, if any, should be universally applied to
all operations with multiple arguments from the same types hierarchy.

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



  reply	other threads:[~2007-05-27 10:04 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-23 19:47 Ada Interfaces and the Liskov Substitution Principle Stefan Lucks
2007-05-23 20:32 ` Ludovic Brenta
2007-05-23 22:00   ` Randy Brukardt
2007-05-24  0:56     ` Anh Vo
2007-05-24 18:27     ` Pascal Obry
2007-05-24 18:39       ` Dmitry A. Kazakov
2007-05-24 18:51         ` Pascal Obry
2007-05-24 22:44         ` Randy Brukardt
2007-05-24  6:57   ` Stefan Lucks
2007-05-23 20:54 ` Maciej Sobczak
2007-05-23 21:58   ` Randy Brukardt
2007-05-24  7:29     ` Maciej Sobczak
2007-05-24  8:02       ` Dmitry A. Kazakov
2007-05-24 12:58         ` Maciej Sobczak
2007-05-24 13:42           ` Dmitry A. Kazakov
2007-05-24 22:08           ` Robert A Duff
2007-07-01  1:00             ` David Thompson
2007-05-24 22:58           ` Randy Brukardt
2007-05-25  7:52             ` Maciej Sobczak
2007-05-25  8:21               ` Dmitry A. Kazakov
2007-05-25 20:27                 ` Maciej Sobczak
2007-05-26  7:48                   ` Dmitry A. Kazakov
2007-05-27  8:30                     ` Maciej Sobczak
2007-05-27 10:04                       ` Dmitry A. Kazakov [this message]
2007-05-29  8:03                         ` Maciej Sobczak
2007-05-29 13:18                           ` Dmitry A. Kazakov
2007-05-29 13:32                             ` Dmitry A. Kazakov
2007-05-29 15:34                             ` Maciej Sobczak
2007-05-29 17:07                               ` Dmitry A. Kazakov
2007-05-30  7:40                                 ` Maciej Sobczak
2007-05-30  8:43                                   ` Dmitry A. Kazakov
2007-05-30 12:54                                     ` Maciej Sobczak
2007-05-30 13:56                                       ` Dmitry A. Kazakov
2007-05-30 16:49                                         ` vgodunko
2007-05-30 20:52                                         ` Maciej Sobczak
2007-05-31  8:15                                           ` Dmitry A. Kazakov
2007-05-31 13:46                                             ` Maciej Sobczak
2007-06-01  7:29                                               ` Dmitry A. Kazakov
2007-06-01 13:32                                                 ` Maciej Sobczak
2007-06-01 14:53                                                   ` Dmitry A. Kazakov
2007-06-01 20:31                                                     ` Maciej Sobczak
2007-06-02  8:19                                                       ` Dmitry A. Kazakov
2007-06-02 16:49                                                         ` Maciej Sobczak
2007-06-03  7:09                                                           ` Dmitry A. Kazakov
2007-06-03 22:04                                                             ` Maciej Sobczak
2007-06-04  8:08                                                               ` Dmitry A. Kazakov
2007-06-04 17:02                                                                 ` Maciej Sobczak
2007-06-05  8:35                                                                   ` Dmitry A. Kazakov
2007-06-05 22:12                                                                     ` Maciej Sobczak
2007-06-06  8:21                                                                       ` Dmitry A. Kazakov
2007-06-06 14:46                                                                         ` Maciej Sobczak
2007-06-06 15:11                                                                           ` Maciej Sobczak
2007-06-06 15:32                                                                       ` Markus E Leypold
2007-05-24 10:42       ` Georg Bauhaus
2007-05-24 13:41         ` Dmitry A. Kazakov
2007-05-25 16:59         ` Markus E Leypold
2007-05-28  9:52           ` Georg Bauhaus
2007-05-28 11:50             ` Dmitry A. Kazakov
2007-05-28 23:32               ` Georg Bauhaus
2007-05-29 12:05                 ` Dmitry A. Kazakov
2007-05-29 13:33                 ` Georg Bauhaus
2007-05-29 17:29                   ` Dmitry A. Kazakov
2007-05-29 20:46                     ` Georg Bauhaus
2007-05-30  7:53                       ` Dmitry A. Kazakov
2007-05-30 13:18                       ` Georg Bauhaus
2007-05-31 10:27                         ` Dmitry A. Kazakov
2007-05-31 11:44                         ` Georg Bauhaus
2007-06-01  7:37                           ` Dmitry A. Kazakov
2007-06-01 10:07                             ` Markus E Leypold
2007-06-01 11:41                             ` Georg Bauhaus
2007-06-01 13:07                               ` Dmitry A. Kazakov
2007-05-28 13:47             ` Markus E Leypold
2007-05-28 23:12               ` Georg Bauhaus
2007-05-28 13:56             ` Markus E Leypold
2007-05-28 23:00               ` Georg Bauhaus
2007-05-24  7:39 ` Dmitry A. Kazakov
2007-05-24 11:12   ` Stefan Lucks
2007-05-24 13:56     ` Dmitry A. Kazakov
2007-05-24 14:41       ` Stefan Lucks
2007-05-24 15:46         ` Dmitry A. Kazakov
2007-05-24 15:00       ` Georg Bauhaus
replies disabled

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