gary@telesoft.UUCP (Gary Dismukes @lizard) (09/24/86)
Implementing equality for limited private access types ------------------------------------------------------ The same technique that is used to implement equality for a limited private type whose full type is derived from type INTEGER can be used when the full type is an access type (or, in fact, any type for which "=" is defined): package P is type LP is limited private; function "=" ( LEFT, RIGHT: LP ) return BOOLEAN; private type ACCESS_TYPE is access SOME_TYPE; type LP is new ACCESS_TYPE; end P; package P is function "=" ( LEFT, RIGHT: LP ) return BOOLEAN is begin return ACCESS_TYPE( LEFT ) = ACCESS_TYPE( RIGHT ); end "="; end P; It is just a matter of introducing a type via a separate type declaration, and then deriving from that type in the private type's full type declaration. From your example it appears that you actually want to define equality for your limited type to be equality of the designated objects. This can be done by implementing the "=" function as follows: function "=" ( LEFT, RIGHT: LP ) return BOOLEAN is begin If ACCESS_TYPE( LEFT ) = null or ACCESS_TYPE( RIGHT ) = null then return FALSE; -- or perhaps: return ACCESS_TYPE( LEFT ) = ACCESS_TYPE( RIGHT ); else return LEFT.all = RIGHT.all; end if; end "="; Also, for efficiency, one might want to compare LEFT and RIGHT directly in the else part before comparing the designated objects in the case of objects that are large: return ACCESS_TYPE( LEFT ) = ACCESS_TYPE( RIGHT ) or else LEFT.all = RIGHT.all; Gary Dismukes TeleSoft gary@telesoft.uucp ucbvax--| hp-sdd--| telesoft!gary@ucsd.arpa decvax--+--sdcsvax--+--telesoft ihnp4--| noscvax--|