From: "Nick Roberts" <Nick.Roberts@dial.pipex.com>
Subject: Re: Tagged Types and Generics
Date: 1997/04/27
Date: 1997-04-27T00:00:00+00:00 [thread overview]
Message-ID: <01bc52a1$a7b80ac0$28f982c1@xhv46.dial.pipex.com> (raw)
In-Reply-To: dewar.862004577@merv
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 prev parent reply other threads:[~1997-04-27 0:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-04-21 0:00 Tagged Types and Generics 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 [this message]
1997-04-28 0:00 ` Robert I. Eachus
1997-04-28 0:00 ` Tom Moran
-- strict thread matches above, loose matches on Subject: below --
1997-04-26 0:00 Robert C. Leif, Ph.D.
1997-04-27 0:00 ` Robert Dewar
1997-05-02 0:00 ` Nick Roberts
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox