[comp.lang.ada] Redefinition of "=" and related issues

MFELDMAN@GWUVM.BITNET (Mike Feldman) (01/02/88)

I wonder if anyone in net-land can give an authoritative discussion on the
issue of redefinition of the "=" operator. I am often asked about this by
students, and have not been able to find an authoritative answer.

In preliminary Ada (as described in the 1979 SIGPLAN issue), it was
apparently permitted to redefine "=" for any type at all (at least I
could find no limitations described there). By the 1980 version of the
language (e.g. the original MIL-STD-1815) redefinition of "=" is
restricted to limited private types (paragraph 6-

Further, in no event is redefinition of ":=" permitted, but the two
operations ":=" and "=" are put in the same class in that both are
available for private types and both are unavailable for limited types.

The consequence is that it is difficult to write certain kinds of packages,
such as for rational numbers (the classical example). In this case you'd
really like to redefine "=" so that 1/2 = 2/4 (as in mathematics). But
normally you'd make the rational type (unlimited) private so as not to
lose the ":=" operation. So we have a devilish choice: make the type
limited private and write a rather foolish-looking and nonuniform
copy operation like ASSIGN(DEST: out RATIONAL; SOURCE: in RATIONAL)
in order to get "=" correct, or make the type unlimited private and
be forced to write a nonuniform equality-checker like
function EQUAL(LEFT, RIGHT: in RATIONAL) return BOOLEAN.
(Note that predefined "=" is still available for the user to (mis)use.
Both solutions are unsatisfying and create interfaces to straightforward
mathematical entities which are nonuniform and unintuitive.

So the basic questions are (1) what was the discussion that led up to
prohibiting redefinition of "=" except for limited types? and (2) why
are "=" and ":=" identified so closely? I do not have the completed new
Rationale; I can find nothing in the 1984 draft Rationale that speaks to
the issue.

Doug Bryan: this might be a good "dear Ada" question. Who can answer?