comp.lang.ada
 help / color / mirror / Atom feed
From: "Marin David Condic" <dont.bother.mcondic.auntie.spam@[acm.org>
Subject: Re: (elementary question) Test on type ?
Date: Tue, 4 Sep 2001 09:30:13 -0400
Date: 2001-09-04T13:30:14+00:00	[thread overview]
Message-ID: <9n2l16$bqv$1@nh.pace.co.uk> (raw)
In-Reply-To: 9n2ctk$36v$1@snipp.uninett.no

What you are trying to do is basically impossible in Ada. You can't have a
generic parameter that is, say, "private" and then try to test to see if the
actual is of type Integer or Float. There are a couple of reasons for this:

One is that there are an infinite number of possible Integer types. You can
declare your own integer types all day long, so how can you build into the
code some sort of test to decide if the type is "Integer" and have that mean
anything? Either it has to test for the *specific* type "Standard.Integer"
in which case it misses all the other infinite number of possible integer
types you can create, or it has to look for all things that exhibit the
characteristics of integers. If the latter is the case, then you're down to:

type X is range <> ;

That way you know it can only be filled by an actual that satisfies the
characteristics of integer types.

But you want to also supply floating point types? Well, then you can't
assume the characteristics of both integer types *and* floating point types
because the sets of characteristics are different in many areas. (There is
no Integer'Machine_Mantissa, for example) You have to go to the next level
up and abstract away everything but the things that are common to both
integer and floating point types. That would be a "private" formal type. You
can't assume math ops or attributes because they are different between
floating and discrete types - so you can only assume what is common to both.

I think this illustrates a minor "hole" in the Ada language design. It would
be nice to have a generic parameter that was somewhere between "private" and
integer, decimal, float, etc. It would be nice to say: "type X is scalar ;"
or similar and know that you can presume "+", "-", and other common math
operations, but not necessarily those that make no sense for all
mathematical types. Just a thought...

MDC
--
Marin David Condic
Senior Software Engineer
Pace Micro Technology Americas    www.pacemicro.com
Enabling the digital revolution
e-Mail:    marin.condic@pacemicro.com
Web:      http://www.mcondic.com/


"Reinert Korsnes" <Reinert.Korsnes@ffi.no> wrote in message
news:9n2ctk$36v$1@snipp.uninett.no...
> Jacob Sparre Andersen wrote:
>
> > Reinert:
> >
> >> >  if X in Integer then
> >>
> >> I get error message "incompatible types".....
> >
> > Then X is apparently not of type Integer. ;-)
> >
> > Seriously, what are you trying to do?
>
> Just do a bit different things in the function depending on the type
> of X.   Say, X is Float of Interger....
>
> Maybe some dirty programming, but anyway.
>
> reinert
>
> >
> > Jacob
>
> --
> http://home.chello.no/~rkorsnes





  parent reply	other threads:[~2001-09-04 13:30 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-09-04  8:41 (elementary question) Test on type ? Reinert Korsnes
2001-09-04  9:18 ` David C. Hoos, Sr.
2001-09-04  9:29   ` Reinert Korsnes
2001-09-04 11:02     ` Jacob Sparre Andersen
2001-09-04 11:05       ` Reinert Korsnes
2001-09-04 11:39         ` John McCabe
2001-09-04 13:30         ` Marin David Condic [this message]
2001-09-04 14:07           ` Ted Dennison
2001-09-04 14:48             ` Marin David Condic
2001-09-04 18:35               ` Mark Biggar
2001-09-04 19:33                 ` Marin David Condic
2001-09-04 14:15         ` Ted Dennison
2001-09-05  9:14           ` John McCabe
2001-09-05 14:19             ` Ted Dennison
2001-09-05 16:24               ` John McCabe
2001-09-05 18:33               ` Ehud Lamm
2001-09-06  9:36           ` Reinert Korsnes
2001-09-06 17:10             ` (elementary question) Test on type ? Pragma inline(granularity)? Warren W. Gay VE3WWG
  -- strict thread matches above, loose matches on Subject: below --
2001-09-04 17:55 (elementary question) Test on type ? Beard, Frank
2001-09-05  9:16 ` John McCabe
replies disabled

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