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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,cea03ed275aa3d28 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Newsgroups: comp.lang.ada Subject: Re: Question about generics. References: <7Q2qg.812592$084.507058@attbi_s22> <44A9495A.7020106@obry.net> From: M E Leypold Date: 04 Jul 2006 08:17:46 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii User-Agent: Some cool user agent (SCUG) NNTP-Posting-Host: 88.72.219.12 X-Trace: news.arcor-ip.de 1151993469 88.72.219.12 (4 Jul 2006 08:11:09 +0200) X-Complaints-To: abuse@arcor-ip.de Path: g2news2.google.com!news4.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.arcor-ip.de!news.arcor-ip.de!not-for-mail Xref: g2news2.google.com comp.lang.ada:5465 Date: 2006-07-04T08:17:46+02:00 List-Id: "Peter C. Chapin" writes: > Pascal Obry 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. Wouldn't it do to check the parameter in the body of the package during elaboration? Admittedly there is overhead and usage errors are not caught by the compiler then, but it would help to avoid more obscure errors later. Regards -- Markus