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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1de1981df403322c X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-11-11 04:34:50 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!elnk-pas-nf1!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!stamper.news.atl.earthlink.net!newsread1.news.atl.earthlink.net.POSTED!d9c68f36!not-for-mail Message-ID: <3FB0D764.5080003@noplace.com> From: Marin David Condic User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.0.1) Gecko/20020823 Netscape/7.0 (OEM-HPQ-PRS1C03) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: New limited range type? References: <20619edc.0311071005.15e6b9a8@posting.google.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Date: Tue, 11 Nov 2003 12:34:49 GMT NNTP-Posting-Host: 209.165.4.125 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.news.atl.earthlink.net 1068554089 209.165.4.125 (Tue, 11 Nov 2003 04:34:49 PST) NNTP-Posting-Date: Tue, 11 Nov 2003 04:34:49 PST Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: archiver1.google.com comp.lang.ada:2338 Date: 2003-11-11T12:34:49+00:00 List-Id: In developing something else, I created a type heierarchy that had a base type "Object" from which you could derive anything, then a type "Ordinal" that required comparison operators, and from that, "Scalar" which required basic math operations. The scalar type had problems when you wanted things like exponentiation, since you then had to pick some integer or real type for various other parameters, but in general it worked nice for the app at hand. You could build something with a collection of things derived from Ordinal and presume to be able to sort them, etc. With the scalars, you could compute statistical data & such on the collection. Very useful and *much* less painful than trying to build generics for float, fixed, decimal, integer, etc. Plus, you could have a type derived from Ordinal or Scalar that had more than just a number associated with it. A record type with ">" or "+" operators defined for it would work just as well so long as you were willing to live with some inefficiency and ambiguity. (What does it *mean* to say "Y := X + Z;" if X, Y and Z are records containing a float plus a string?) Perhaps there is a way to imply a type heierarchy on Ada types that would allow generics to handle any ordinal or scalar type & get the presumption of various comparison & math operators. Going with tagged types instead of generics lets you get there, but there is a certain amount of awkwardness and extra work involved. (You've got to have abstract functions for all the operators and then you have to fill them in, etc.) I'm not sure what the syntax would look like or how the language would handle the operators, but it would allow the development of generics for math and sorting needs without having to make all sorts of duplications of the code. MDC Martin Dowie wrote: > > You'll note that from my example, you need different versions for > fixed/float and scalers - it would be nice if there was a generic > formal type parameter that allowed you to specify any *scaler*. > > Perhaps you could mention that to ada-comment too? :-) -- ====================================================================== Marin David Condic I work for: http://www.belcan.com/ My project is: http://www.jsf.mil/NSFrames.htm Send Replies To: m o d c @ a m o g c n i c . r "Trying is the first step towards failure." -- Homer Simpson ======================================================================