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 15:33:37 -0400
Date: 2001-09-04T19:33:39+00:00	[thread overview]
Message-ID: <9n3aaj$l7c$1@nh.pace.co.uk> (raw)
In-Reply-To: 3B951F33.927CA445@home.com

You can get there via a variety of ways. One of my favorites is to declare
an abstract tagged private type that has "+", "-", etc. as abstract
functions. You can then use a generic formal that is of the 'Class of that
tagged type. A user then derives from the abstract class and supplies the
operations. That saves you from making a long generic formal list at the
expense of making a long abstract function list. Don't know that there is a
huge advantage to either one.

But none of the possible solutions is as "clean" as simply having a "type X
is scalar ;" generic formal parameter. (or some similar mechanism.) If Ada
is smart enough to detect the operations for the actual parameter anyway,
then maybe I don't have to do the work. That's always A Good Thing.

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/


"Mark Biggar" <mark.a.biggar@home.com> wrote in message
news:3B951F33.927CA445@home.com...
>
> 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);
>






  reply	other threads:[~2001-09-04 19:33 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
2001-09-04 19:33                 ` Marin David Condic [this message]
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