comp.lang.ada
 help / color / mirror / Atom feed
From: jsa@organon.com (Jon S Anthony)
Subject: Re: Real OO
Date: 1996/05/07
Date: 1996-05-07T00:00:00+00:00	[thread overview]
Message-ID: <JSA.96May6211900@organon.com> (raw)
In-Reply-To: DqywnJ.4y8@assip.csasyd.oz


In article <DqywnJ.4y8@assip.csasyd.oz> donh@syd.csa.com.au (Don Harrison) writes:

> Jon,
>
> Stepping back to your original example, I'd like to clarify a few
> things before commenting on it (again).
>
> :The example in Ada:
> :
> :package Drivers is
> :    type Driver is tagged private;
> :....
> :end Drivers;
> :
> :package Drivers.Cars is
> :    type Car_Driver is new Driver with private;
> :....
> :end Drivers.Cars;
> :
> :package Drivers.Trucks is
> :    type Truck_Driver is new Driver with private;
> :....
> :end Drivers.Trucks;
> :
> :
> :
> :with Drivers;  use Drivers;
> :package Vehicles is
> :    type Vehicle is tagged private;
> :
> :    procedure Register_Driver (V: Vehicle; D: Driver);
>
> I assume this syntax is correct. That is, you don't have to say
> Driver'Class?  The status of D would be clearer, IMO, if you had to
> write Driver'Class.

Yes, it is "correct", you don't need (and here you pretty clearly do
not _want_) to say Driver'Class.  As the example was proposed, there
is no need to use Driver'Class.  Instead of being "clearer", its use
would be confusing and probably just plain wrong.

> :    procedure Renew_Rego_By_Mail (V: Vehicle);
> :....
> :end Vehicles;
> :
> :with Drivers.Cars; use Drivers.Cars;
> :package Vehicles.Cars is
> :    type Car is new Vehicle with private;
> :
> :    procedure Register_Driver (V: Vehicle; D: Car_Driver);
> :....
> :end Vehicles.Cars;
> :
> :with Drivers.Trucks; use Drivers.Trucks;
> :package Vehicles.Trucks is
> :    type Truck is new Vehicle with private;
> :
> :    procedure Register_Driver (T: Truck; D: Truck_Driver);
> :    procedure Renew_Rego_By_Inspection(T: Truck);
> 
> Presumably, Register_Driver does not override the implementation for Vehicle
> because of RM 6.3.1(15) and 8.3(8,9)?

Visibility doesn't really enter into it (8.3 stuff) but 6.3.1(15)
pretty much hits it.  Truck_Driver and Driver are two _different_
types.  The fact that they both belong in Driver'Class is not relevant
to the declarations or implementation of operations of these two
_specific_ types.  It _is_ relevant to an _invocation_ of such
operations where classwide operand(s) happen to be specified.

> :....
> :end Vehicles.Trucks;
> :
> :
> :-- In a client somewhere
> :--
> :    D: Driver;
> :    Cd: Car_Driver;
> :    V: Vehicle;
> :    T: Truck;
> :....
> :    -- Option 1.
> :    --
> :    D := Cd; -- Illegal, compile time error
> :    V := T;  -- Illegal, compile time error
> :
> :    -- Option 2.
> :    --
> :    D := Driver(Cd); -- OK, convert toward root
> :    V := Vehicle(T); -- OK, convert toward root
> 
> I understand these are view conversions, but am wondering how this can be 
> implemented without reference semantics?

Actually these are about the only example of such conversions which
are not view conversions.  All of the types involved are specific
types and so the conversion "does the right thing" and merely changes
the corresponding components of D and V to the values present in Cd
and T.  In no case are the tags (dynamic type) changed.  In
particular, no truncation occurs.  View conversions (the most typical
case...) when used in an invocation (the most typical case again...)
_do_ use reference semantics.  For example, the "better" way to have
written the above Option 2 would have been to skip the D and V decls
and the assignments and simply have written:

    Register_Driver(Vehicle(T), Driver(Cd)); -- Reference semantics...

> :    Register_Driver(V, D); -- just fine and no dispatch needed
> 
> Is this this call statically bound to the implementation for Vehicle?

Absolutely.  That's the point of this option.


> :    -- Option 3.
> :    --
> :    Register_Driver(Vehicle'Class(T),Cd); -- Compile error, no primitive ops
> 
> ... for type Truck with formal parameter Car_Driver?

Not quite - Vehicle has no primitive operations with _car_ drivers - only
"generic" _drivers_.


> :    -- Option 4.
> :    --
> :    Register_Driver(Truck'Class(T), Cd);  -- Compile error, no primitive ops
> 
> ... for type Truck with formal parameter Car_Driver?

Yes, exactly.  There are only operations for <Truck,Driver> and
<Truck,Truck_Driver> pairs.


> :    -- Option 6.
> :    --
> :    Register_Driver(Vehicle'Class(V), D); -- Fine
> :    Register_Driver(Vehicle'Class(T), D); -- Fine (calls inherited op!!)
> 
> Shouldn't the first one be:
> 
>     Register_Driver(Truck'Class(T), D);   -- Fine

Depends on what you mean.  As written the first one is just fine.  All
vehicles are in Vehicle'Class and D is delcared as a driver and there
is a primitive Register_Driver op for the pair <vehicle,Driver> which
is inherited (and possibly overridden) for every vehicle (note the non
capitalized spelling of vehicle here).  And as written your version is
just fine for completely similar reasons (just substitute "truck" for
"vehicle" and Truck for Vehicle.)  From a legality point of view -
neither have any legality issues, they are perfectly valid and "do the
right thing."


> :As you can see, you can't get the invalid system stuff in the Ada model.
> :In particular, you should note that the Truck type has _two_ primitive
> :operations Register_Driver:
> :
> : procedure Register_Driver(V: Truck; D: Driver); -- Inherited from Vehicle
> : procedure Register_Driver(V: Truck; D: Truck_Driver); -- *New* primitive op
>
> And, shouldn't these be:
> 
>:procedure Register_Driver(V: Vehicle; D: Driver); -- Inherited from Vehicle
>:procedure Register_Driver(T: Truck; D: Truck_Driver); -- *New* primitive op

The V in the second of mine should be a T as you have in your second
as that is how it is declared in Vehicles.Trucks (though it _could_
have been given as a "V").  So, for this one, I made a typo...  This
is _really_ unfortunate as it probably just served to confuse you.
Sorry.

This really was a bad typo because the first one is quite correct as
given and is the more important (and less obvious) bit. Vehicle and
Truck are different _specific_ types and a specific type only covers
itself.  In a derivation an inherited operation is obtained from the
parent version by "systematic replacement" of the corresponding types
in the signature.  Admittedly this is not particularly obvious to the
casual observer.  See 3.4(18-23) for the precise definition.  From a
"pragmatic" point of view, the important thing is to realize that
there is indeed a new operation for the derived type with a signature
specifying the new _specific_ type that is the derived type.


/Jon
-- 
Jon Anthony
Organon Motives, Inc.
1 Williston Road, Suite 4
Belmont, MA 02178

617.484.3383
jsa@organon.com





  parent reply	other threads:[~1996-05-07  0:00 UTC|newest]

Thread overview: 218+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <4id031$cf9@dayuc.dayton.saic.com>
1996-03-18  0:00 ` Real OO Norman H. Cohen
1996-03-18  0:00   ` The Right Reverend Colin James III
1996-03-19  0:00     ` Norman H. Cohen
1996-03-20  0:00       ` Norman Cohen giving IBM a bad name The Right Reverend Colin James III
1996-03-20  0:00         ` Dave Retherford
1996-03-20  0:00         ` Real OO Dale Stanbrough
1996-03-21  0:00           ` Richard Pitre
1996-03-20  0:00         ` Colin James III giving humans a bad name (was Re: Norman Cohen giving IBM a bad name) David Emery
1996-03-20  0:00           ` Mark R Okern - F95
1996-03-20  0:00             ` Real OO John G. Volan
1996-03-21  0:00               ` Scott Leschke
1996-03-21  0:00                 ` Robert A Duff
1996-03-21  0:00                 ` Norman H. Cohen
1996-03-22  0:00                 ` Don Harrison
1996-03-21  0:00             ` Colin James III giving humans a bad name (was Re: Norman Cohen giving IBM a bad name) Richard A. O'Keefe
1996-03-21  0:00               ` Robert Dewar
1996-03-20  0:00         ` Norman Cohen giving IBM a bad name Brian & Karen Bell
1996-03-21  0:00         ` Kent Mitchell
1996-03-22  0:00         ` Robert Munck
1996-03-22  0:00           ` Mark Brennan
1996-03-22  0:00             ` David Curry
1996-03-23  0:00         ` Tom Reid
1996-03-21  0:00       ` Real OO Don Harrison
1996-03-21  0:00   ` Colin James III giving humans a bad name (was Re: Norman Cohen giving IBM a bad name) Ulrich Windl
1996-03-20  0:00 ` Real OO Don Harrison
1996-03-22  0:00 ` Don Harrison
1996-03-22  0:00   ` Norman H. Cohen
1996-03-27  0:00     ` Don Harrison
1996-03-27  0:00       ` Norman H. Cohen
1996-03-28  0:00         ` Jacob Gore
1996-04-04  0:00         ` Don Harrison
1996-04-04  0:00           ` Tucker Taft
1996-04-04  0:00             ` Tucker Taft
1996-04-12  0:00               ` Don Harrison
1996-04-12  0:00             ` Don Harrison
1996-04-15  0:00               ` Robert I. Eachus
1996-04-19  0:00                 ` Don Harrison
1996-04-19  0:00                   ` Matt Kennel
1996-04-20  0:00                     ` Bob Hathaway
1996-04-23  0:00                     ` Don Harrison
1996-04-04  0:00           ` Jon S Anthony
1996-04-04  0:00           ` Laurent Guerby
1996-04-04  0:00           ` Robb Nebbe
1996-03-22  0:00   ` Norman H. Cohen
1996-03-26  0:00     ` Don Harrison
1996-03-26  0:00       ` Norman H. Cohen
1996-03-29  0:00         ` Don Harrison
1996-03-27  0:00       ` Thomas Beale
1996-03-28  0:00         ` Don Harrison
1996-03-23  0:00   ` Joachim Durchholz
1996-03-26  0:00     ` Norman H. Cohen
1996-04-04  0:00       ` Don Harrison
1996-04-04  0:00         ` Jon S Anthony
1996-04-12  0:00           ` Don Harrison
1996-04-17  0:00             ` Jon S Anthony
1996-04-19  0:00               ` Don Harrison
1996-04-19  0:00                 ` Multiple Dispatch in Ada 95 (Was Re: Real OO) Brian Rogoff
1996-04-21  0:00                   ` Brian Rogoff
1996-04-19  0:00                 ` Real OO Jon S Anthony
1996-04-23  0:00                   ` Don Harrison
1996-04-24  0:00                     ` Don Harrison
1996-04-29  0:00                     ` Jon S Anthony
1996-04-30  0:00                       ` Robert Dewar
1996-04-30  0:00                         ` Robert A Duff
1996-04-30  0:00                           ` Robert Dewar
1996-05-01  0:00                             ` Richard Bielak
1996-04-30  0:00                           ` Amit Patel
1996-05-01  0:00                           ` Adam Beneschan
1996-05-02  0:00                             ` Ell
1996-04-30  0:00                         ` Amit Patel
1996-04-30  0:00                           ` Robert A Duff
1996-05-07  0:00                             ` Amit Patel
1996-05-01  0:00                           ` Norman H. Cohen
1996-05-01  0:00                             ` Colin James III (The Rt Rev'd)
1996-05-07  0:00                             ` Amit Patel
1996-05-01  0:00                         ` Don Harrison
1996-05-01  0:00                           ` David Hopwood
1996-05-03  0:00                             ` Don Harrison
1996-05-01  0:00                           ` Don Harrison
1996-05-02  0:00                             ` Robert A Duff
1996-05-03  0:00                               ` Don Harrison
1996-05-03  0:00                                 ` Robert A Duff
1996-05-06  0:00                                   ` Don Harrison
1996-05-06  0:00                                     ` Robert A Duff
1996-05-06  0:00                                     ` Robb Nebbe
1996-05-02  0:00                           ` Robert A Duff
1996-05-03  0:00                             ` Don Harrison
1996-05-10  0:00                             ` Don Harrison
1996-05-01  0:00                         ` AdaWorks
1996-05-08  0:00                         ` Joachim Durchholz
1996-05-03  0:00                       ` Don Harrison
1996-05-03  0:00                         ` Dave Fitch
1996-05-07  0:00                         ` Jon S Anthony
1996-04-30  0:00                     ` Joachim Durchholz
1996-04-30  0:00                     ` Jon S Anthony
1996-05-01  0:00                       ` Matt Kennel
1996-05-03  0:00                         ` Don Harrison
1996-05-02  0:00                       ` Don Harrison
1996-05-02  0:00                         ` Robert I. Eachus
1996-05-02  0:00                         ` Jon S Anthony
1996-05-03  0:00                           ` Don Harrison
1996-05-06  0:00                             ` Jon S Anthony
1996-05-06  0:00                         ` Jon S Anthony
1996-05-06  0:00                       ` Don Harrison
1996-05-06  0:00                         ` Don Harrison
1996-05-07  0:00                         ` Jon S Anthony [this message]
1996-05-13  0:00                           ` Don Harrison
1996-05-09  0:00                         ` Jon S Anthony
1996-04-19  0:00                 ` Multiple Dispatch in Ada 95 (Was Re: Real OO) Robert I. Eachus
1996-04-20  0:00                 ` Brian Rogoff
1996-04-21  0:00                   ` Robert A Duff
1996-04-24  0:00                 ` Real OO Joachim Durchholz
1996-05-01  0:00                   ` Matt Kennel
1996-05-02  0:00                     ` Don Harrison
1996-05-07  0:00                   ` Joachim Durchholz
1996-05-08  0:00                   ` Jon S Anthony
1996-05-09  0:00                   ` Robert I. Eachus
1996-04-30  0:00                 ` Joachim Durchholz
1996-05-08  0:00                   ` Joachim Durchholz
1996-05-10  0:00                   ` Jon S Anthony
1996-04-30  0:00                 ` Jon S Anthony
1996-05-03  0:00                   ` Don Harrison
1996-05-07  0:00                     ` Jon S Anthony
1996-05-02  0:00                 ` Jon S Anthony
1996-05-06  0:00                 ` Jon S Anthony
1996-04-08  0:00         ` Norman H. Cohen
1996-04-08  0:00           ` Robert A Duff
1996-04-09  0:00             ` Norman H. Cohen
1996-04-10  0:00           ` Don Harrison
1996-04-11  0:00           ` Jacob Gore
1996-04-12  0:00           ` Don Harrison
1996-04-12  0:00             ` Matt Kennel
1996-04-15  0:00               ` Don Harrison
1996-04-12  0:00             ` Jon S Anthony
1996-04-13  0:00               ` Robert A Duff
1996-04-16  0:00             ` Jon S Anthony
1996-04-12  0:00           ` Don Harrison
1996-04-12  0:00             ` Jacob Gore
1996-04-16  0:00               ` Don Harrison
1996-04-09  0:00         ` Jon S Anthony
1996-04-09  0:00         ` Valery CROIZIER
1996-04-09  0:00       ` Joachim Durchholz
1996-05-02  0:00       ` Joachim Durchholz
1996-05-05  0:00         ` Robert A Duff
1996-05-05  0:00           ` Robert Dewar
1996-05-06  0:00         ` Norman H. Cohen
1996-05-07  0:00           ` Don Harrison
1996-05-07  0:00             ` Jon S Anthony
1996-05-08  0:00               ` Don Harrison
1996-05-08  0:00             ` Norman H. Cohen
1996-05-08  0:00               ` Robert A Duff
1996-05-10  0:00                 ` Matt Kennel
1996-05-10  0:00                   ` Robert A Duff
1996-05-14  0:00                     ` Matt Kennel
1996-05-15  0:00                       ` Robert A Duff
1996-05-07  0:00           ` Ada terminology (was Re: Real OO) David Hopwood
1996-05-07  0:00             ` The Right Reverend Colin James III
1996-05-07  0:00             ` Dave Jones
1996-05-07  0:00             ` Tucker Taft
1996-05-07  0:00               ` The Right Reverend Colin James III
1996-05-08  0:00               ` bill.williams
1996-05-07  0:00         ` Real OO Amit Patel
1996-05-07  0:00           ` The Right Reverend Colin James III
1996-05-08  0:00           ` Don Harrison
1996-05-08  0:00             ` Juergen Schlegelmilch
     [not found]               ` <Dr4538.D27@assip.csasyd.oz>
1996-05-09  0:00                 ` Richard Riehle
1996-05-10  0:00                   ` Tucker Taft
1996-05-13  0:00                     ` Don Harrison
1996-05-13  0:00                       ` Tucker Taft
1996-05-14  0:00                         ` Joachim Durchholz
1996-05-14  0:00                         ` Roger Browne
1996-05-14  0:00                         ` Don Harrison
1996-05-14  0:00                           ` Robert A Duff
1996-05-14  0:00                           ` Steve Tynor
1996-05-14  0:00                             ` Robert A Duff
1996-05-15  0:00                             ` Don Harrison
1996-05-15  0:00                           ` Steve Tynor
1996-05-15  0:00                             ` Robert A Duff
1996-05-16  0:00                           ` James McKim
1996-05-18  0:00                             ` Matt Kennel
1996-05-20  0:00                               ` James McKim
1996-05-22  0:00                                 ` Matt Kennel
1996-05-15  0:00                         ` Steve Tynor
1996-05-15  0:00                         ` Alexander Kjeldaas
1996-05-19  0:00                         ` Piercarlo Grandi
1996-05-14  0:00                   ` James McKim
1996-05-15  0:00                     ` Juergen Schlegelmilch
1996-05-09  0:00                 ` Juergen Schlegelmilch
1996-05-20  0:00               ` Joachim Durchholz
1996-05-07  0:00       ` Joachim Durchholz
1996-05-09  0:00         ` Don Harrison
1996-05-09  0:00           ` Jon S Anthony
1996-05-09  0:00           ` Joachim Durchholz
1996-04-02  0:00     ` Detecting type mismatch at compile time (was Re: Real OO) Robert I. Eachus
1996-04-03  0:00       ` Richard Bielak
1996-04-04  0:00       ` Don Harrison
1996-03-28  0:00   ` Real OO Joachim Durchholz
1996-03-29  0:00     ` Norman H. Cohen
1996-03-30  0:00       ` John G. Volan
1996-03-26  0:00 ` Jon S Anthony
1996-03-29  0:00 ` Joachim Durchholz
1996-04-04  0:00   ` Don Harrison
1996-04-04  0:00     ` Steve Tynor
1996-04-08  0:00       ` Norman H. Cohen
1996-04-09  0:00         ` Matt Kennel
1996-04-04  0:00     ` Dominique Colnet
1996-04-08  0:00     ` Matt Kennel
1996-04-09  0:00       ` Norman H. Cohen
1996-04-09  0:00     ` Robert C. Martin
1996-04-10  0:00     ` J. Kanze
1996-05-02  0:00 Bob Crispen
     [not found] <DoDLr7.JDB@world.std.com>
     [not found] ` <4if7s5$bfk@ra.nrl.navy.mil>
     [not found]   ` <DoDqH4.29v@world.std.com>
1996-03-26  0:00     ` AdaWorks
1996-03-29  0:00   ` Brian Rogoff
     [not found] <4hneps$1238@watnews1.watson.ibm.com>
     [not found] ` <Do3F1K.4xG@assip.csasyd.oz>
     [not found]   ` <4i455s$ijq@watnews1.watson.ibm.com>
1996-03-15  0:00     ` Don Harrison
     [not found]       ` <DoBH80.9u9@world.std.com>
1996-03-15  0:00         ` Richard Pitre
1996-03-15  0:00         ` Mark A Biggar
1996-03-16  0:00     ` Des  Kenny
     [not found] <JSA.96Mar13143956@organon.com>
1996-03-15  0:00 ` Don Harrison
replies disabled

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