comp.lang.ada
 help / color / mirror / Atom feed
From: Marin David Condic <nobody@noplace.com>
Subject: Re: New limited range type?
Date: Tue, 11 Nov 2003 12:34:49 GMT
Date: 2003-11-11T12:34:49+00:00	[thread overview]
Message-ID: <3FB0D764.5080003@noplace.com> (raw)
In-Reply-To: af783afe.0311110235.5c865027@posting.google.com

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

======================================================================




      parent reply	other threads:[~2003-11-11 12:34 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-07 15:51 New limited range type? Martin Dowie
2003-11-07 15:57 ` Hyman Rosen
2003-11-07 16:20   ` Martin Dowie
2003-11-07 16:36     ` Stephane Richard
2003-11-07 16:59     ` Hyman Rosen
2003-11-07 18:18       ` Martin Dowie
2003-11-07 20:11         ` Larry Hazel
2003-11-07 22:40           ` Martin Dowie
2003-11-07 23:31             ` Larry Hazel
2003-11-12  8:22       ` Jean-Pierre Rosen
2003-11-12 15:00         ` Hyman Rosen
2003-11-12 15:34           ` Robert I. Eachus
2003-11-12 17:37             ` tmoran
2003-11-07 18:19   ` Mike Silva
2003-11-07 19:03   ` Marin David Condic
2003-11-07 18:05 ` Mike Silva
2003-11-08 21:58   ` Nick Roberts
2003-11-09 14:34     ` Martin Dowie
2003-11-11  5:13       ` Nick Roberts
2003-11-11 10:18         ` Martin Dowie
2003-11-11 10:35         ` Martin Dowie
2003-11-11 10:41           ` Lutz Donnerhacke
2003-11-11 12:37             ` Marin David Condic
2003-11-11 14:19             ` Martin Dowie
2003-11-11 12:34           ` Marin David Condic [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox