From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,cea03ed275aa3d28 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Question about generics. Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <7Q2qg.812592$084.507058@attbi_s22> Date: Mon, 3 Jul 2006 22:18:53 +0200 Message-ID: NNTP-Posting-Date: 03 Jul 2006 22:18:47 MEST NNTP-Posting-Host: 552c87b2.newsread4.arcor-online.net X-Trace: DXC=I[g_9aF2^2mXiD6\]5e5en:ejgIfPPlddjW\KbG]kaMhLL]:kiR8f=ohbTJVI 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