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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID 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: "Robert C. Leif, Ph.D." Subject: Re: Tagged Types and Generics Date: 1997/04/26 Message-ID: <3.0.32.19970426224603.00702f6c@mail.4dcomm.com>#1/1 X-Deja-AN: 237656231 Sender: Ada programming language X-Sender: rleif@mail.4dcomm.com Comments: To: Nick.Roberts@DIAL.PIPEX.COM Newsgroups: comp.lang.ada Date: 1997-04-26T00:00:00+00:00 List-Id: 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 Subject: Re: Tagged Types and Generics 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. ------------------------------