comp.lang.ada
 help / color / mirror / Atom feed
From: mark_biggar@my-deja.com
Subject: Re: Disallowing Pre-Defined Operations
Date: 2000/03/10
Date: 2000-03-10T00:00:00+00:00	[thread overview]
Message-ID: <8ab99b$m4i$1@nnrp1.deja.com> (raw)
In-Reply-To: 8a9eeg$qtv$1@newpoisson.nosc.mil

In article <8a9eeg$qtv$1@newpoisson.nosc.mil>,
  claveman@cod.nosc.mil (Charles H. Sampson) wrote:
>      During the deliberations that led to Ada 95, was a mechanism for
> disallowing the pre-defined operations of a type considered?
By "disal-
> lowing" I mean some way of informing the compiler that an attempt to
use
> a certain pre-defined operation is a compile-time error.  Did anyone
> even ask for it?  (Obviously I didn't, even though I've thought since
> the mid-eighties that it would be a useful capability to have.)
>
>      As an example of what I'm talking about, consider a package that
> implements three distinct floating-points types for measuring length,
> area, and volume.  The pre-defined "+" and "-" are acceptable and
there
> are obvious redefinitions of "*" and "/" in some cases.  However, the
> pre-defined "/" for operands of the same type don't make sense and it
> would be nice to get a compile-time warning if one of them is used.
> Yes, a redefinition that raises an exception can be written, but
that's
> not the same thing.
>
>      In the case that's bothering me at the moment, my project has a
> type called Time_Type.  (We can't be assured that Ada's built-in time
> types are adequate for our purposes.)  We've already had one fairly
dif-
> ficult bug because a variable of this type was used to hold the
differ-
> ence between two values of the type, known in our environment as a
> delta-time.  Now defining a new type Delta_Time_Type and the set of
Cal- endar-like operations is no big deal, but I have no way of telling
the
> compiler to flag such things as the pre-defined
>
>           function "-" (L, R : Time_Type) return Time_Type;
>
> and the "*", "/", and "**" operations on values of these types.
>
>      Declaring the types as private doesn't work.  The types are
inher-
> ently (and obviously) numeric and nobody on my project would want to
> lose the ability to use numeric literals when appropriate.  (Every
time
> this issue has popped up for me over the last 15+ years, it's been in
> the context of numeric types.)  Whenever time I come up with a way of
> pluging one hole, it opens another.  For example, overloading "-" as
>
>     function "-" (L : Time_Type; R : Float) return Delta_Time_Type;
>
> would allow any value of type Float to be subtracted, not just
literals.
>
>      Does it tell you something about my project when I say that if
the
> above definition of "-" were used, I'm sure somebody would discover
the
> hole and figure out some "clever" way of exploiting it?

Easy: just define the operator as abstract.  E.g.,:

type Length is new Integer;

function "*"(Left,Right: Length) return Length is abstract;
function "/"(Left,Right: Length) return Length is abstract;

-- now we define what we really want

function "/"(left,Right: Length) return Integer;

type Area is new Integer;

function "*"(Left,Right: Length) return Area;

-- etc.

--
Mark Biggar
mark@biggar.org


Sent via Deja.com http://www.deja.com/
Before you buy.




  parent reply	other threads:[~2000-03-10  0:00 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-03-10  0:00 Disallowing Pre-Defined Operations Charles H. Sampson
2000-03-09  0:00 ` Keith Thompson
2000-03-09  0:00 ` Samuel T. Harris
2000-03-12  0:00   ` Steven Hovater
2000-03-10  0:00 ` Jean-Pierre Rosen
2000-03-11  0:00   ` Tarjei Tj�stheim Jensen
2000-03-11  0:00     ` James S. Rogers
2000-03-13  0:00       ` Tarjei T. Jensen
2000-03-13  0:00     ` dmitry6243
2000-03-13  0:00     ` Robert Dewar
2000-03-13  0:00       ` Keith Thompson
2000-03-15  0:00         ` Robert Dewar
2000-03-15  0:00     ` Charles H. Sampson
2000-03-15  0:00       ` Robert Dewar
2000-03-21  0:00         ` Charles H. Sampson
2000-03-21  0:00           ` Robert A Duff
2000-03-21  0:00           ` Robert Dewar
2000-03-12  0:00   ` claveman
2000-03-12  0:00     ` Robert A Duff
2000-03-13  0:00       ` Tarjei T. Jensen
2000-03-13  0:00         ` Robert Dewar
2000-03-13  0:00         ` Robert A Duff
2000-03-15  0:00       ` Charles H. Sampson
2000-03-15  0:00         ` Tucker Taft
2000-03-15  0:00           ` Paul Graham
2000-03-16  0:00             ` Charles Hixson
2000-03-17  0:00               ` Paul Graham
2000-03-17  0:00                 ` Charles Hixson
2000-03-18  0:00                   ` Robert Dewar
2000-03-20  0:00                     ` Charles Hixson
2000-03-20  0:00                       ` Robert Dewar
2000-03-16  0:00             ` Robert Dewar
2000-03-16  0:00           ` Bryce Bardin
2000-03-16  0:00           ` Tarjei T. Jensen
2000-03-16  0:00             ` Dale Stanbrough
2000-03-16  0:00             ` mark_biggar
2000-03-17  0:00         ` Robert A Duff
2000-03-13  0:00     ` Ted Dennison
2000-03-10  0:00 ` mark_biggar [this message]
2000-03-14  0:00 ` Nick Roberts
2000-03-15  0:00   ` Robert Dewar
2000-03-17  0:00 ` William A Whitaker
2000-03-18  0:00   ` Robert Dewar
2000-03-18  0:00   ` Robert Dewar
2000-03-18  0:00   ` Robert Dewar
2000-03-22  0:00     ` William A Whitaker
2000-03-23  0:00       ` Robert Dewar
2000-04-06  0:00         ` Robert I. Eachus
2000-04-05  0:00           ` Marin D. Condic
2000-04-06  0:00             ` Robert Dewar
2000-04-06  0:00               ` Marin D. Condic
2000-04-07  0:00                 ` dale
2000-04-07  0:00                   ` Marin D. Condic
2000-04-07  0:00                     ` Tarjei T. Jensen
2000-04-07  0:00                       ` Marin D. Condic
2000-04-07  0:00                         ` tmoran
2000-04-07  0:00                           ` Marin D. Condic
2000-04-08  0:00                             ` Vladimir Olensky
2000-04-08  0:00                             ` Vladimir Olensky
2000-04-08  0:00                         ` Dale Stanbrough
2000-04-10  0:00                         ` Tarjei T. Jensen
2000-04-15  0:00                         ` Niklas Holsti
2000-04-15  0:00                           ` Marin D. Condic
2000-04-07  0:00                 ` Robert Dewar
2000-04-07  0:00                   ` Marin D. Condic
2000-04-09  0:00               ` Robert I. Eachus
replies disabled

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