comp.lang.ada
 help / color / mirror / Atom feed
From: "Yannick Duchêne (Hibou57)" <yannick_duchene@yahoo.fr>
Subject: Re: Parameterless generic instance in place of opaque type instance
Date: Sun, 28 Jul 2013 09:26:44 +0200
Date: 2013-07-28T09:26:44+02:00	[thread overview]
Message-ID: <op.w0w8autyule2fv@cardamome> (raw)
In-Reply-To: op.w0w658dmule2fv@cardamome

Le Sun, 28 Jul 2013 09:02:22 +0200, Yannick Duchêne (Hibou57)  
<yannick_duchene@yahoo.fr> a écrit:
> 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‑paquage 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‑package 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 :=
             (Sample.Reference);
        procedure Receive_A_Parameter
          (Reference : Sample.Reference_Type)
        is begin
           Sample.Operation (Reference);
        end;
     begin
        Receive_A_Parameter (Reference);
     end;


-- 
“Syntactic sugar causes cancer of the semi-colons.” [1]
“Structured Programming supports the law of the excluded muddle.” [1]
[1]: Epigrams on Programming — Alan J. — P. Yale University


  reply	other threads:[~2013-07-28  7:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-28  5:49 Parameterless generic instance in place of opaque type instance Yannick Duchêne (Hibou57)
2013-07-28  6:36 ` Yannick Duchêne (Hibou57)
2013-07-28  7:02   ` Yannick Duchêne (Hibou57)
2013-07-28  7:26     ` Yannick Duchêne (Hibou57) [this message]
2013-07-28  7:30 ` J-P. Rosen
2013-07-28  8:24   ` Yannick Duchêne (Hibou57)
2013-07-28 18:08     ` Shark8
2013-07-28 19:47       ` Yannick Duchêne (Hibou57)
2013-07-28 20:58         ` Shark8
2013-07-28 22:27           ` Yannick Duchêne (Hibou57)
2013-07-28 21:15         ` J-P. Rosen
2013-07-28 22:23           ` Shark8
2013-07-28 14:52 ` Robert A Duff
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox