From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: *** X-Spam-Status: No, score=3.8 required=5.0 tests=BAYES_00,INVALID_MSGID, RATWARE_MS_HASH,RATWARE_OUTLOOK_NONAME autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,fcdd0f6139250dc5 X-Google-Attributes: gid103376,public From: "Nick Roberts" Subject: Re: Tagged Types and Generics Date: 1997/04/27 Message-ID: <01bc52a1$a7b80ac0$28f982c1@xhv46.dial.pipex.com>#1/1 X-Deja-AN: 237609512 References: <3.0.32.19970421225247.007129f4@mail.4dcomm.com> Organization: UUNet PIPEX server (post doesn't reflect views of UUNet PIPEX) Newsgroups: comp.lang.ada Date: 1997-04-27T00:00:00+00:00 List-Id: Robert Dewar wrote in article ... > Bob Leif says > > < 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.