From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Question about generics.
Date: Wed, 5 Jul 2006 14:08:08 +0200
Date: 2006-07-05T14:08:08+02:00 [thread overview]
Message-ID: <r4nm482r7hr8.15cu9grd5slqt.dlg@40tude.net> (raw)
In-Reply-To: uirmdsdkr.fsf@nasa.gov
On Tue, 04 Jul 2006 09:29:40 -0400, Stephen Leake wrote:
> That does seem like a reasonable goal. But I think you need to modify
> the language to get there. Perhaps a new class of generic parameters:
>
> generic
> Size : static Integer;
> package Xyzzy_Static is
> type Index is mod Size;
> -- etc.
> end Xyzzy_Static;
>
> Then Xyzzy_Static could only be instantiated with truly static Size
> (in the Ada meaning of 'static').
>
> Short of that, I think you have to declare the type outside the
> generic package, as you say.
>
> I often find it better to declare the type outside the package,
> because I want it for things the package doesn't declare. But if you
> intend to put everything into the generic, it would be nice to do it
> your way.
>
> It would be interesting to raise the 'static' proposal on the Ada
> comment mailing list (where they discuss future changes to the Ada
> language). But to do that right, I'd need more information about why
> you want to do this. Their mostly likely response will be "it's not
> hard to declare the type outside the package". So we need some more
> ammunition about why that's not a good answer.
It is more interesting for cases unrelated to generics:
User-defined static functions:
function Factorial (N : static Natural) return static Natural;
type My_Strange_Type is mod Factorial (5);
function C_Compiler (X : static String) return static Float;
C : constant Float :=
C_Compiler ("/* some C program */ float x=2.0; for(;;){...");
-- Evaluated by the compiler at compile-time.
function Number_Quarks_Requred_On_This_Mashine
( OS : static String;
CPU : static String;
...
) return static Quark_Number;
function To_UTF8 (X : static String) return static String;
while Current_Line = To_UTF8 ("...") loop
...; -- Manual constant folding is always possible, though
end loop;
type EEPROM is array (...) of Storage_Elements;
Boot : static EEPROM := Link (C_Compiler (...));
for Boot'Address use ...;
if Pure were a qualifier instead of pragma, then static result could be
made implied from static parameters. I have difficulty to classify "static"
as a type qualifier. Is static X is subtype, new type or what.
Dimensioned arithmetic:
type Unit is mod 2**28; -- Encoded powers of base units
type Dimensioned (SI : Unit) record
Gain : Float;
end record;
function "+" (Left, Right : Dimensioned) return Dimensioned;
function "-" (Left, Right : Dimensioned) return Dimensioned;
function "*" (Left, Right : Dimensioned) return Dimensioned;
function "/" (Left, Right : Dimensioned) return Dimensioned;
...
type Static_Dimensioned (SI : static Unit) is new Dimensioned (SI);
-- Statically constrained Dimensioned, the compiler is *required* to
-- drop the discriminant in the representation of. When converted
-- back to Dimensioned, the discriminant is reconstructed. Forward
-- conversion is compile-time type error, when the discriminant
-- isn't static.
function "+" (Left, Right : Static_Dimensioned)
return Static_Dimensioned;
function "-" (Left, Right : Static_Dimensioned)
return Static_Dimensioned;
function "*" (Left, Right : Static_Dimensioned)
return Static_Dimensioned;
function "/" (Left, Right : Static_Dimensioned)
return Static_Dimensioned;
...
I think you've got the idea. This gives you dimensioned arithmetic fully
statically checkable, space/time penalty free, which also can handle
unknown dimensions at run-time.
But there are too many problems with this. Note how important are partially
static types like Static_Dimensioned. Just one type qualifier "static" does
not solve the problem. It must be much finer.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2006-07-05 12:08 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
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 [this message]
-- 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