From: "Robert C. Leif, Ph.D." <rleif@RLEIF.COM>
Subject: Re: Tagged Types and Generics
Date: 1997/04/26
Date: 1997-04-26T00:00:00+00:00 [thread overview]
Message-ID: <3.0.32.19970426224603.00702f6c@mail.4dcomm.com> (raw)
To: Nick Roberts et al.
From: Bob Leif
I am absolutely in agreement with you and what you posted below! I was
going to add the last_update date and time to money. The discussion has
never been tagged types versus generics. It has been about constructing a
tagged type with generic fields and instantiating a generic with a tagged
type which can include generic fields. Both constructs are very useful and
should NOT be mutually exclusive. Unfortunately, I do not know how to do
it. Even if Nick Roberts and I are both dead wrong on money, it is still
necessary to explain how to combine tagged types with generics.
I might add that part of the problem is historical. The text books first
explain generics, which existed in Ada 83 and then the Ada 95 addition,
tagged types. I have not seen a generic in a tagged type with a class-wise
procedure or operator. Is very nice to start with a money tagged type and
then create many children: US_Dollars, Canadian_Dollars, Yen,
Deutsch_Marks, Italian_Lira, Turkish_Lira, Gold_Oz, etc. This is much
cleaner than a variant record with over 50 values for the discriminant. A
tagged type also provides the possibility of using wide characters and
different methods for showing negative values.
-------------------------------------------------------------
Date: Sun, 27 Apr 1997 00:49:14 GMT
From: Nick Roberts <Nick.Roberts@DIAL.PIPEX.COM>
Subject: Re: Tagged Types and Generics
Robert Dewar <dewar@merv.cs.nyu.edu> wrote in article
<dewar.862004577@merv>...
> Bob Leif says
>
> <<Background: Recently, Tom Moran, Randy Brukard and I wrote a paper.
"Ada
> 95, The Language Speaks for Itself". This paper will appear in the May
> Object Magazine. In this paper we modeled money as a decimal type and
did
> inheritance directly via a generic. I had suggested modeling money as a
> tagged type. My co-authors very wisely vetoed that approach. After
the>>
>
> I can't see any reason for wanting to model money as a tagged type -- you
> lose literals, and you lose a lot of other useful semantics of decimal
> types, and you gain nothing that I can see.
I think I can see a few possibilities: for example, what if you wanted to
be able to use multiple currencies easily? You can get literals reasonably
easily by the use of simple conversion functions. For example:
package Money is
type General_Monetary_Amount is limited private;
type US_Dollars is delta 0.01 digits 12;
type Lire is delta 100 digits 14;
...
function To_General(Amount: in US_Dollars) return
General_Monetary_Amount;
function To_General(Amount: in Lire) return General_Monetary_Amount;
...
private
...
end;
and then a 'literal' can be constructed with something like
To_General(US_Dollars'(59.23))
This is slightly clumsy, of course, but not too bad.
If we had defined General_Monetary_Amount as tagged, we could extend it,
perhaps to provide a date (for aiding exchange calculations):
package Money.Dated is
type Dated_Monetary_Amount is new General_Monetary_Amount;
...
private
type Dated_Monetary_Amount is new General_Monetary_Amount with
record
Date: Calendar.Time;
end record;
end;
And so on. Just thoughts (and it's gone midnight).
Nick.
------------------------------
next reply other threads:[~1997-04-26 0:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-04-26 0:00 Robert C. Leif, Ph.D. [this message]
1997-04-27 0:00 ` Tagged Types and Generics Robert Dewar
1997-05-02 0:00 ` Nick Roberts
-- strict thread matches above, loose matches on Subject: below --
1997-04-21 0:00 Robert C. Leif, Ph.D.
1997-04-24 0:00 ` Jeff Carter
1997-04-25 0:00 ` Robert Dewar
1997-04-26 0:00 ` Matthew Heaney
1997-04-26 0:00 ` Tom Moran
1997-04-27 0:00 ` Nick Roberts
1997-04-28 0:00 ` Robert I. Eachus
1997-04-28 0:00 ` Tom Moran
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox