comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Question about generics.
Date: Mon, 3 Jul 2006 22:18:53 +0200
Date: 2006-07-03T22:18:47+02:00	[thread overview]
Message-ID: <dv4t30a6porw.1r47tofvyu5ws$.dlg@40tude.net> (raw)
In-Reply-To: dKeqg.18133$FQ1.16604@attbi_s71

On Mon, 03 Jul 2006 20:03:21 GMT, Jeffrey R. Carter wrote:

> Peter C. Chapin wrote:
>> 
>> Why not a compile time error when the instantiation is attempted?
> 
> Because the legality of a generic unit is determined when the generic is 
> compiled, not when it is instantiated. That the generic formal of Size 
> allows non-positive values is yet another reason this specific example 
> would be illegal, even if Size were static.

Right. But it is the problem of Ada, that "static Positive" cannot be
expressed as a [formal] type. If that were possible then the generic unit
could be checked before instantiation. There are also other cases where
that would be useful. For example, for forcing constant folding at compile
time (necessary for statically dimensioned values.)

>> 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; 
>> it only exists to pass size information into the generic package. That 
>> seems pretty counter-intuitive and awkward. I guess I was hoping Ada 
>> would have a nicer solution... generic parameters that are named numbers 
>> or something.
> 
> I find this hard to accept. The reason to declare a visible type in the 
> generic is so that the client can use the type from an instantiation to 
> call operations of the type provided by the generic.

I don't think it is a good argument. The types declared in the visible part
of Xyzzy can be referred as Fizzle.Type_Declared_Inside.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2006-07-03 20:18 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
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 [this message]
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