comp.lang.ada
 help / color / mirror / Atom feed
From: "Peter C. Chapin" <pchapin@sover.net>
Subject: Re: Question about generics.
Date: 04 Jul 2006 01:09:23 GMT
Date: 2006-07-04T01:09:23+00:00	[thread overview]
Message-ID: <Xns97F5D743FCA17pchapinsovernet@198.186.192.137> (raw)
In-Reply-To: 44A9495A.7020106@obry.net

Pascal Obry <pascal@obry.net> wrote in news:44A9495A.7020106@obry.net:

>> Yes. However, this means at the point of instantiation I have to do 
>> something like
>> 
>>          type Dummy_Type is mod 8;
>>          package Fizzle is new Xyzzy(Index => Dummy_Type);
>> 
>> The Dummy_Type will never be used in the context of the
>> instantiation; 
> 
> Why won't it be used? If you pass it to the generic there lot of
> chances that some function/procedure will be passed such a type, no ?
> And so the  type will be used on the client code too...

Well, in my situation the type is an implementation detail. It does not
appear in the interface to the generic package. The user of the generic
package can't do anything useful with the type. 

Actually the Size parameter isn't part of the (functional) interface
either. However it will impact the performance characteristics of the
package and thus Size is interesting to the clients. That is why I'd
like to parameterize it. I can see how to accomplish this, but I don't
think what I tried originally is particularly odd or unreasonable. 

I guess the issue, as has been pointed out by others, is that Ada wants
to be sure the generic package will instantiate correctly if the
arguments provided obey the constraints that have been specified in the
generic parameters. However, the generic parameter "language" isn't
quite expressive enough to say what I want to say ("only allow positive
constants") and so my first approach isn't accepted. 

I can see that the C++ approach, which defers the detection of errors
until instantiation time, allows a bit more flexibility in this
respect... at the expense of cryptic error messages when something goes
wrong. In any case I've found this discussion interesting and
educational. I'd like to thank all of those who have participated. 

Peter



  reply	other threads:[~2006-07-04  1:09 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-02 16:08 Question about generics Peter C. Chapin
2006-07-02 18:49 ` Martin Krischik
2006-07-03  6:30 ` Jeffrey R. Carter
2006-07-03 10:33   ` Peter C. Chapin
2006-07-03 11:42     ` Jean-Pierre Rosen
2006-07-03 16:44     ` Pascal Obry
2006-07-04  1:09       ` Peter C. Chapin [this message]
2006-07-04  6:17         ` M E Leypold
2006-07-04 10:48           ` Peter C. Chapin
2006-07-03 20:03     ` Jeffrey R. Carter
2006-07-03 20:18       ` Dmitry A. Kazakov
2006-07-04  0:08         ` Randy Brukardt
2006-07-04  7:48           ` Dmitry A. Kazakov
2006-07-04  0:43         ` Jeffrey R. Carter
2006-07-03  9:46 ` Martin Krischik
2006-07-04 13:29 ` Stephen Leake
2006-07-05 12:08   ` Dmitry A. Kazakov
  -- strict thread matches above, loose matches on Subject: below --
1993-09-02 17:45 question " Stef  Van Vlierberghe
1993-08-12 15:18 Robert I. Eachus
1993-08-11 18:48 cis.ohio-state.edu!magnus.acs.ohio-state.edu!math.ohio-state.edu!howland.
1993-08-11  0:25 agate!howland.reston.ans.net!europa.eng.gtefsd.com!darwin.sura.net!seas.g
1993-08-10 15:53 Robert I. Eachus
1993-08-09 21:29 Kenneth Anderson
1989-05-29 20:54 Question " "14827_DAVID PAPAY"
1989-05-29  7:02 "Jonathan B. Owen"
replies disabled

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