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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,30fad28eb8886cca X-Google-Attributes: gid103376,public From: emwson@emw.ericsson.se (Martin Lorentzon) Subject: Re: parameterless generics? Date: 1996/07/18 Message-ID: #1/1 X-Deja-AN: 169458525 sender: emwson@hera.emw.ericsson.se references: <4s48k9$3be$1@mhafn.production.compuserve.com> organization: Ericsson Microwave Systems newsgroups: comp.lang.ada Date: 1996-07-18T00:00:00+00:00 List-Id: In article <4s48k9$3be$1@mhafn.production.compuserve.com>, Brian Gilbert <71413.1453@CompuServe.COM> writes: |> Does anybody have a reason to use a generic (package or |> subprogram) without a parameter? How about getting the accessibility level right when extending tagged types? A small example: ====================================================================== -- This package is not generic because it needn't be. package Foo is type Root is tagged null record; end Foo; ====================================================================== -- This package needs to be generic for some reason. with Foo; generic type Element is private; package Foobar is type Child is new Foo.Root with null record; end Foobar; ====================================================================== -- Now we can't instansitate the foobar package. -- Compiling the `bar' procedure is an error: with Foo; with Foobar; procedure Bar is package Fb is new Foobar(Float); begin null; end Bar; ====================================================================== Rewriting the `Foo' package as a generic package solves the problem: ====================================================================== -- Now the package Foo is generic and takes no parameters. It's -- generic only to used as a parameter to foobar: generic package Foo is type Root is tagged null record; end Foo; ====================================================================== -- Package Foobar now takes an instantiation of package Foo as a -- generic parameter to avoid getting the type extension at a deeper -- accessibility level than the parent: with Foo; generic type Element is private; with package Foo_Inst is new Foo; package Foobar is type Child is new Foo_Inst.Root with null record; end Foobar; ====================================================================== -- Finally we let the `Bar' procedure take care of the instantiations: with Foo; with Foobar; procedure Bar is package F is new Foo; package Fb is new Foobar(Float,F); begin null; end Bar; -- Regards, -- Martin.