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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 Path: border1.nntp.dca3.giganews.com!border2.nntp.dca3.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!goblin3!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail From: =?utf-8?Q?Yannick_Duch=C3=AAne_=28Hibou57?= =?utf-8?Q?=29?= Newsgroups: comp.lang.ada Subject: Re: Parameterless generic instance in place of opaque type instance Date: Sun, 28 Jul 2013 09:26:44 +0200 Organization: Ada @ Home Message-ID: References: NNTP-Posting-Host: ds8m8HfAx594C0h4s/JFyA.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: Quoted-Printable X-Complaints-To: abuse@aioe.org User-Agent: Opera Mail/12.16 (Linux) X-Notice: Filtered by postfilter v. 0.8.2 X-Original-Bytes: 3238 Xref: number.nntp.dca.giganews.com comp.lang.ada:182731 Date: 2013-07-28T09:26:44+02:00 List-Id: Le Sun, 28 Jul 2013 09:02:22 +0200, Yannick Duch=C3=AAne (Hibou57) = a =C3=A9crit: > Say a GADO still defines an ADT, with an unknown discriminant, so that= = > it cannot be instantiated without initialization. What the private = > declares, is just an access type to a deferred type (defined in the = > body). The body defines an instance of the type it fully defines. The = = > package offers a single function returning an (opaque) access to this = = > unique and per=E2=80=91paquage instance, instance. The function could = be named = > `Instance_Reference`, to clearly show it's always the same behind, = > however a new distinct one per generic instance (not strictly a = > singleton, a per=E2=80=91package singleton). I should have posted an Ada sample, to be more meaningful. Here is: generic package Samples is type Reference_Type (<>) is private; function Reference return Reference_Type; procedure Operation (Reference : Reference_Type); private type Data_Type; type Reference_Type is not null access all Data_Type; end; package body Samples is type Data_Type is record null; end record; Data : aliased Data_Type; function Reference return Reference_Type is (Data'Access); procedure Operation (Reference : Reference_Type) is begin null; end; end; procedure Use_A_Sample is package Sample is new Samples; Reference : Sample.Reference_Type :=3D (Sample.Reference); procedure Receive_A_Parameter (Reference : Sample.Reference_Type) is begin Sample.Operation (Reference); end; begin Receive_A_Parameter (Reference); end; -- = =E2=80=9CSyntactic sugar causes cancer of the semi-colons.=E2=80=9D [1] =E2=80=9CStructured Programming supports the law of the excluded muddle.= =E2=80=9D [1] [1]: Epigrams on Programming =E2=80=94 Alan J. =E2=80=94 P. Yale Univers= ity