From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Reemergence of predefined equality operator...
Date: Wed, 31 Jul 2002 22:47:43 GMT
Date: 2002-07-31T22:47:43+00:00 [thread overview]
Message-ID: <wcc7kjb1pm8.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: dstanbro-DB04BE.08254201082002@news-server.bigpond.net.au
Dale Stanbrough <dstanbro@bigpond.net.au> writes:
> I was demonstrating what i thought would be the reemergence of
> the predefined equality operator by doing...
>
> type text is... (record with length & chars, like bounded string)
> function "=" (a, b : text) return boolean;
>
>
> and
>
>
> generic
> type element is private;
> with function "=" (a, b : element) return boolean is <>;
> package...
>
> and after instantiating the generic with type text it kept calling
> the "=" defined for type text.
>
> I thought Ada (through a bad design decision) said that it should call
> the predefined "=" opertor in this instance. Has this been changed,
> or do have I misunderstood the problem?
You've misunderstood the problem. ;-)
Above, you passed in a formal "=" explicitly. The "is <>" means that
the default is to pass in whatever "=" happens to be visible at the
place of the instantiaation (and has the right profile types). That is
probably the user-defined "=" that you wanted. In that case, the
"problem" does not occur.
The "problem" is when you leave out the explicit ``with function
"="...''. Then type "element" has a predefined "=" (because it's
private, not limited private). In that case, the predefined "=" of the
actual type "reemerges". In other words, if you instantiate with
Element => T, and T has a primitive user-defined "=", the instance will
call the predefined "=" rather than the user-defined one.
If you wanted to drive a stake through the heart of the predefined "="
by declaring a user-defined "=", so that every time objects of type T
are compared for equality it will call the user-defined "=", then you
lose -- if you pass T to a generic or wrap T in a record, the predefined
"=" reemerges (rises from the dead).
For "=", this seems "obviously" wrong. But as I pointed out elsewhere,
the situation for other operators (eg, "mod"), is not so obvious.
Even if the language were changed, or even if Text_IO.Integer_IO took
"mod" as an "is <>" parameter as above, it's not clear (to me) what the
right answer is.
- Bob
next prev parent reply other threads:[~2002-07-31 22:47 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-07-31 22:25 Reemergence of predefined equality operator Dale Stanbrough
2002-07-31 22:47 ` Robert A Duff [this message]
2002-08-01 1:30 ` Vincent Marciante
2002-08-01 12:06 ` Robert Dewar
2002-08-25 17:46 ` Vincent Marciante
2002-08-25 22:04 ` Robert A Duff
2002-08-01 11:14 ` Dale Stanbrough
2002-08-01 14:48 ` Robert A Duff
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox