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: a07f3367d7,12d893e9461dcfe6 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.224.209.202 with SMTP id gh10mr394232qab.2.1344267971220; Mon, 06 Aug 2012 08:46:11 -0700 (PDT) Received: by 10.66.82.2 with SMTP id e2mr1367424pay.40.1344262879731; Mon, 06 Aug 2012 07:21:19 -0700 (PDT) Path: c6ni65261628qas.0!nntp.google.com!r1no10402661qas.0!news-out.google.com!g9ni19524583pbo.0!nntp.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!novia!feeder3.cambriumusenet.nl!feeder1.cambriumusenet.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!news.panservice.it!newsfeed.tele2net.at!newsfeed.utanet.at!feeder2.cambriumusenet.nl!feed.tweaknews.nl!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Access to generic formal parameters in an generic package instantiation Date: Mon, 30 Jul 2012 11:33:21 -0700 (PDT) Organization: http://groups.google.com Message-ID: <383e776c-f377-4ede-8560-cbb54fde3c87@googlegroups.com> References: <87a9yi5t7j.fsf@mid.deneb.enyo.de> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 X-Trace: posting.google.com 1343673202 28667 127.0.0.1 (30 Jul 2012 18:33:22 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 30 Jul 2012 18:33:22 +0000 (UTC) In-Reply-To: <87a9yi5t7j.fsf@mid.deneb.enyo.de> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-Received-Bytes: 4490 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-07-30T11:33:21-07:00 List-Id: On Sunday, July 29, 2012 11:16:00 AM UTC-7, Florian Weimer wrote: > If G is a generic package and P is one of its formal parameters, it is > legal to refer to G.P where G is visible?=20 No, unless you're inside G. Outside of G, you can't refer to any entities = inside G. I wonder if you're referring to a generic *instance*, though. It's helpful= to keep the terminology straight: generic type T is private; package Gen_Package is ... package Instance is new Gen_Package (Integer); -- for example Gen_Package is a "generic package". Outside of Gen_Package, you can't refe= r to Gen_Package.T and it wouldn't make any sense. Instance is not a "gene= ric package"; it's a "generic instance", or an "instance of a generic packa= ge". However, you still can't refer to Instance.T. I think the theory was proba= bly that the code knows what Instance.T is because it's right there in the = parameter list when Gen_Package is instantiated, so it isn't necessary to a= llow Instance.T. =20 In this case generic with INST is new Gen_Package (<>); package Gen_Package_2 is ... INST is a "generic formal package", not a "generic package". It represents= an instance of Gen_Package, but of course we don't know what the instance = is until we instantiate Gen_Package_2. Within Gen_Package_2, you can refer= to INST.T, because (unlike the previous example) the code in Gen_Package_2= doesn't know what INST.T is, because there's only a <> in the parameter li= st of the generic formal package declaration. Hope this helps a little, > Does this depend on the > kind of entity, or whether the formal part uses <>? >=20 >=20 >=20 > Has anybody tried to use generic formal packages to emulate Standard >=20 > ML signatures? Is it possible to express SML "where" constraints,=20 > that is, specify that two types in two formal packages are the same, > without break down the formal packages to their components? You can do something like this: generic with package INST is new Gen_Package (<>); with package ANOTHER_INST is new Another_Gen_Package (T =3D> Inst.T); package Gen_Package_3 is ... Now when you instantiation=20 package Some_Inst is new Gen_Package_3 (P1, P2); the instantiation is legal only if P1 and P2 were instantiated with the sam= e type for T. This seems like what you're looking for. (P.S. This sort of= thing is also legal starting with Ada 2005: generic with package INST is new Gen_Package (<>); with package ANOTHER_INST is new Another_Gen_Package (T =3D> Inst.T, others =3D> <>); package Gen_Package_3 is ... =20 That puts a constraint on the type T used to instantiate Another_Gen_Packag= e, while not putting any constraints on any other actual parameters.) Hope this helps a little, -- Adam