comp.lang.ada
 help / color / mirror / Atom feed
* Redefined "=" = generic disaster?
@ 2000-10-21  6:59 Vincent Marciante
  2000-10-21  0:00 ` Jeff Carter
  0 siblings, 1 reply; 20+ messages in thread
From: Vincent Marciante @ 2000-10-21  6:59 UTC (permalink / raw)


In Ada 83, one could specify/declare a generic formal private type and
then compare objects of that type without any problems - the only
instance where the concept of equality could be changed is for limited
private types.  So in effect, when one specified a private formal one
got the equality operator as a side effect and could utilize it without
any surprises.

Now however, in Ada 95, one _can_ redefine equality for "any type at
all".  Therefore, all generic unit code that previously "safely"
utilized "=" of a generic formal nonlimitted type may now cause
unexpected results.

For example if one now has an Ada 95 abstraction such as 

package Ada_95_Assignable_Thing is
     type Thing is private; 
     function "=" (Left, Right : Thing) return Boolean;
     ...  
end; 

One might expect to be able to use it when instantiating an old, fully
tested generic unit that was written in Ada 83 and that compiles cleanly
without any warnings and that has a spec such as 

generic
    type Something is private;
package Ada_83_Abstract_Data_Type is
    type ADT is private;
    ...
    function Is_Equal (L,R: ADT) return Boolean;
end;
package body Ada_83_Abstract_Data_Type is
    ...
    function Is_Equal (L,R: ADT) return Boolean;
    begin
        return L = R;
    end;
end;

package Instance_Ada_83_ADT is 
    new Ada_83_Abstract_Data_Type(Ada_95_Assignable_Thing);


My point is that, because everything could compile correctly, one would
expect that the primative "=" for type "Thing" would be utilized in
"Is_Equal" but it is not.  Yes, I know that people can "expect" may
things that "clear" ;) should not be expected but isn't this as bad as
the problem with unconstrained formal types that was fixed in Ada 95? 
The problem here is (said with a Brooklyn accent;) "The spec asked for a
private type, so thats what I gave it but the program don't work????"

Aspects (or all?) of this have been discuss under previous threads
regarding "reemergence of predefined operators" and the lawyers have
stated that is good reason for it but could find discussion specifically
about "=".   Would not having "=" reemerge be bad?  If only "=" did not
reemerge then this possibly wide spread problem with old code would not
be an issue.

BTW, I not interested in arguments that the old Ada 83 code was actually
incorrect when it first written.  I am interested in finding out wats to
update it so that it works as one would expect ;) in Ada 95.   All I can
think of now is ethier add 

  function "=" (L,R: Private_Type) return Boolean is "="; 

to all generic parts of the old code for all formal private types in the
generic part or examine all of the bodies and search for usage of "=" of
the private type and then add

  function "=" (L,R: Private_Type) return Boolean; 

to their generic part.

So, after all of this, what is the best way to fix the old code?

Vinny

P.S. Wow its late, I hope (all/most;) of the above makes sense!



^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2000-11-05  4:32 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-10-21  6:59 Redefined "=" = generic disaster? Vincent Marciante
2000-10-21  0:00 ` Jeff Carter
2000-10-21  0:00   ` Vincent Marciante
2000-10-22  2:50     ` Jeff Carter
2000-10-22  0:00       ` Vincent Marciante
2000-10-21  0:00   ` Vincent Marciante
2000-10-28 11:12     ` Robert Dewar
2000-10-29  8:43       ` Vincent Marciante
2000-10-30  3:49       ` Lao Xiao Hai
2000-10-30 18:46         ` Robert Dewar
2000-10-31  3:27           ` Lao Xiao Hai
2000-10-31  6:54             ` Vincent Marciante
2000-10-31 19:51             ` Robert Dewar
2000-11-01 17:47               ` Mats Weber
2000-11-02  5:27                 ` Vincent Marciante
2000-11-02 16:52                   ` Mats Weber
2000-11-02 14:59                 ` Tucker Taft
2000-11-05  4:29                   ` Robert Dewar
2000-11-05  4:32                   ` Robert Dewar
2000-11-05  4:26                 ` Robert Dewar

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