From: Mark Biggar <mark.a.biggar@home.com>
Subject: Re: (elementary question) Test on type ?
Date: Tue, 04 Sep 2001 18:35:37 GMT
Date: 2001-09-04T18:35:37+00:00 [thread overview]
Message-ID: <3B951F33.927CA445@home.com> (raw)
In-Reply-To: 9n2pka$e44$1@nh.pace.co.uk
Marin David Condic wrote:
>
> O.K. O.K. O.K. - You got me there. But that's sort of a deeper technical
> area than what I think the original question was aimed at. (Sounded more
> like a newbie with a more basic question than might be answered by tagged
> records)
>
> I'd agree that if Ada were more of a "purely OO language" it probably would
> have started deriving all of its types from some base type & generic
> parameters might have had more adaptable characteristics. Its been
> frustrating for me to deal with certain math-oriented packages where I've
> essentially had to create more-or-less identical code for integer types,
> fixed types, floating types and decimal types. Lots of math can be done
> sticking only to the operations common to all of the above and if they were
> all derived from some class called "Scalar" (or had a suitable generic
> formal) you could get there a lot easier.
>
> 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/
>
> "Ted Dennison" <dennison@telepath.com> wrote in message
> news:le5l7.3173$4z.4905@www.newsranger.com...
> >
> > Actually it is doable, if the type in question is a tagged type. In that
> case
> > you can easily do something like:
> >
> > if Object_A in Parent_Type_X'class then ....
> >
> > The reason this won't work for Integer is that Integer isn't tagged. Thus:
> >
> > 1) You can't use 'Class on it (or a subtype of it).
> > 2) You can't pass it into a routine that can also take other types for the
> same
> > parameter.
> >
> > I suppose you would be able to do that with Integer if Ada had a type
> system
> > where every type was derived from some common root type. I think there are
> some
> > languages out there that work that way. Ada just isn't one of them.
> >
You can do almost what you want using a generic package using a private
generic type and explicitly defining the operators you want to use.
For example if your package only needs "+", "*", "-", "=", "<".
generic
type Scalar is private;
with function "+"(Left, Right: Scalar) return Scalar is <>;
with function "="(Left, Right: Scalar) return Boolean is <>;
with function "-" ... ;
with function "<" ... ;
package Special_Math is
...
end Special_Math;
package Special_Int is new Special_Math(Scalar => Integer);
package Special_Float is new Special_Math(Scalar => Float);
--
Mark Biggar
mark.a.biggar@home.com
next prev parent reply other threads:[~2001-09-04 18:35 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
2001-09-04 14:07 ` Ted Dennison
2001-09-04 14:48 ` Marin David Condic
2001-09-04 18:35 ` Mark Biggar [this message]
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