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 Path: g2news2.google.com!news4.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!198.186.190.247.MISMATCH!news-out.readnews.com!news-xxxfer.readnews.com!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Question about generics. From: "Peter C. Chapin" References: <7Q2qg.812592$084.507058@attbi_s22> <44A9495A.7020106@obry.net> Organization: Kelsey Mountain Software Message-ID: User-Agent: Xnews/5.04.25 Date: 04 Jul 2006 01:09:23 GMT NNTP-Posting-Host: d578efec.news.sover.net X-Trace: DXC=>4EH83?@`i3kGa5;\7a4AJ= 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. 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