comp.lang.ada
 help / color / mirror / Atom feed
* working with diferent instances of the same generic interface
@ 2015-09-08 15:10 Aitor Alcrudo Sangros
  2015-09-08 17:11 ` G.B.
  2015-09-09  6:38 ` Jacob Sparre Andersen
  0 siblings, 2 replies; 16+ messages in thread
From: Aitor Alcrudo Sangros @ 2015-09-08 15:10 UTC (permalink / raw)


Hi, my google-fu can't find how to do this. I think it should be doable but I'm not 100% sure. I'm thankful if anyone helps.

I have a generic interface some of my tagged records instance, similar to:

package Intro is
   type Data_type is interface;

   generic
      type Readable_Data is abstract new Data_type with private;
   package Readable is
      type Readable_Element is interface;
      type Readable_Element_Access is access all Readable_Element'Class ;
      function Get_Values (this : Readable_Element ) return Readable_Data'Class
                         is abstract;
   end Readable;

   type state is (OK,KO);

     generic
      with package Readable_Reporting is new Readable(<>);
      use Readable_Reporting ;
   package Reporting is
      type Reporting_Element is interface and Readable_Element ;
      type Reporting_Element_Access is access all Reporting_Element'Class;
      function Report (This :Reporting_Element  ) return state is Abstract;
      overriding function Get_Values (this : Reporting_Element ) return
          Readable_Data'Class is abstract;
   end Reporting;
end Intro;

This has worked with no problem. 
I instance it like this
   SomeData is new Data_type with record
     a :float;
   end record;

   package Readable is new Intro.Readable(
      readable_data =>SomeData);
   package Reporting is new Intro.Reporting(Readable);

   type Element_type_A is new Readable.Readable_Element
     				and Reporting.Reporting_Element 
   						with record
      data :float;
   end record;
   type Element_type_A_Access is access all Element_type_A 'Class;

Now, I have something like this

package Reporter is
   package Readable_basic is new Intro.Readable(Data_type );
   package Reporting_basic is new Intro.Reporting(Readable);
   use Reporting;
   type manager is tagged private;
   procedure Add_Element( This : in out manager ;
                         Element : in Reporting_Element_Access );
private
   package Element_Vector is new
     Ada.Containers.Vectors (Natural,Reporting_Element_Access );
   use Element_Vector ;

   type manager  is tagged record
      Element_List : Element_Vector.Vector;
   end record;
end Reporter ;

this compiles.

Now I try to use it elsewhere

procedure try is
   man :manager ;
   elm1 : Element_type_A_Access ;
   elm2 : Element_type_B_Access ;
begin
   man.add(Reporter.Reporting_basic.Reporting_Element_Access(elm1)  );
   man.add(Reporter.Reporting_basic.Reporting_Element_Access(elm2)  );
end;

This compiles, but produces a runtime exception with invalid interface conversion.

Is there any way to get this to work?.




































^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: working with diferent instances of the same generic interface
  2015-09-08 15:10 working with diferent instances of the same generic interface Aitor Alcrudo Sangros
@ 2015-09-08 17:11 ` G.B.
  2015-09-09  6:38 ` Jacob Sparre Andersen
  1 sibling, 0 replies; 16+ messages in thread
From: G.B. @ 2015-09-08 17:11 UTC (permalink / raw)


On 08.09.15 17:10, Aitor Alcrudo Sangros wrote:

> procedure try is
>     man :manager ;
>     elm1 : Element_type_A_Access ;
>     elm2 : Element_type_B_Access ;
> begin
>     man.add(Reporter.Reporting_basic.Reporting_Element_Access(elm1)  );
>     man.add(Reporter.Reporting_basic.Reporting_Element_Access(elm2)  );
> end;
>
> This compiles, but produces a runtime exception with invalid interface conversion.
>
> Is there any way to get this to work?.


Not sure, after skimming. (It looks like a C++ design written
using Ada syntax, although there is a formal tagged type in
the first template's parameters ;-)

I think the problem may be one of trying to convert half-a-bee
into half-a-frog. That's in try's block of statements, where the
other half would be Reporting_Element. But, by the above remark,
I'm not sure. Simplifying, I can get GNAT in trouble using this
program, trying to expose what I think the conversion of elm1
and elm2 amounts to:

procedure Test_Tp is

    package Tp is

       type X is interface;

       type A is tagged null record;
       type B is tagged null record;

       type C is new A and X with null record;
       type D is new B and X with null record;

    end Tp;


    use Tp;

    type X_Ptr is access all X'Class;
    Item : X_Ptr := new D;

    Z : X'Class := X(Item.all);  -- <-- Here
begin
    null;
end Test_Tp;

The running program show memory access failures on some
platforms, referring to the line marked "<-- Here".

Starting gdb, after compiling the library with the program,
I see

Program received signal SIGSEGV, Segmentation fault.
0x000000000040e017 in ada.tags.displace (this=(system.address) 
0x7fffffffd408, t=0x7fffffffdf48 (test_tp.tp.x)) at 
/home/bauhaus/opt/GNAT2014/lib/gcc/x86_64-pc-linux-gnu/4.7.4/adainclude/a-tags.adb:375
375	      Obj_DT_Tag  := To_Tag_Ptr (Obj_Base).all;

So, one might conclude that to much multiple inheritance is
involved...


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: working with diferent instances of the same generic interface
  2015-09-08 15:10 working with diferent instances of the same generic interface Aitor Alcrudo Sangros
  2015-09-08 17:11 ` G.B.
@ 2015-09-09  6:38 ` Jacob Sparre Andersen
  2015-09-09 11:08   ` Aitor Alcrudo Sangros
  1 sibling, 1 reply; 16+ messages in thread
From: Jacob Sparre Andersen @ 2015-09-09  6:38 UTC (permalink / raw)


Aitor Alcrudo Sangros wrote:

> Hi, my google-fu can't find how to do this. I think it should be
> doable but I'm not 100% sure. I'm thankful if anyone helps.

Your examples don't compile.  Please post a compilable version.

Also.  It appears to me that you can omit using access types completely.

Greetings,

Jacob
-- 
There only exist 10 kinds of people: Those who know binary
numbers and those who don't know binary numbers.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: working with diferent instances of the same generic interface
  2015-09-09  6:38 ` Jacob Sparre Andersen
@ 2015-09-09 11:08   ` Aitor Alcrudo Sangros
  2015-09-09 12:17     ` Egil H H
  2015-09-10 12:22     ` Jacob Sparre Andersen
  0 siblings, 2 replies; 16+ messages in thread
From: Aitor Alcrudo Sangros @ 2015-09-09 11:08 UTC (permalink / raw)


El miércoles, 9 de septiembre de 2015, 8:38:18 (UTC+2), Jacob Sparre Andersen  escribió:
> Aitor Alcrudo Sangros wrote:
> 
> > Hi, my google-fu can't find how to do this. I think it should be
> > doable but I'm not 100% sure. I'm thankful if anyone helps.
> 
> Your examples don't compile.  Please post a compilable version.
> 
> Also.  It appears to me that you can omit using access types completely.
> 
> Greetings,
> 
> Jacob
> -- 
> There only exist 10 kinds of people: Those who know binary
> numbers and those who don't know binary numbers.

Hi, I'm not really specifically tring to make that code work as is. What I want to know is how can I work with different instances of the same generic interface, doing things like iterating over a collection of them. This is a minimal example of how I am (unsuccessfully ) tring to do so. Anyway this code compiles, then has a runtime exception.

with Ada.Containers.Vectors;
with Ada.Text_IO;   Use Ada.Text_IO;
procedure test is       
   
   package Intro is 
      type Data_type is interface; 

      generic 
         type Readable_Data is abstract new Data_type with private; 
      package Readable is 
         type Readable_Element is interface; 
         type Readable_Element_Access is access all Readable_Element'Class ; 
         function Get_Values (this : Readable_Element ) return Readable_Data'Class 
                           is abstract; 
      end Readable; 

      type state is (OK,KO); 

      generic 
         with package Readable_Reporting is new Readable(<>); 
         use Readable_Reporting ; 
      package Reporting is 
         type Reporting_Element is interface and Readable_Element ; 
         type Reporting_Element_Access is access all Reporting_Element'Class; 
         function Report (This :Reporting_Element  ) return state is Abstract; 
         overriding function Get_Values (this : Reporting_Element ) return 
           Readable_Data'Class is abstract; 
      end Reporting; 
   end Intro; 
  -- use Intro;
   
   
   --ELEMENT A
   type SomeData is new Intro.Data_type with record 
     a :float; 
   end record; 
	
   package Readable_Some is new Intro.Readable( 
      readable_data =>SomeData); 
   package Reporting_Some is new Intro.Reporting(Readable_Some); 
   type Element_type_A is new Readable_Some.Readable_Element 
                                     and Reporting_Some.Reporting_Element 
   with record 
      data :SomeData := SomeData'(a => 0.0 ); 
   end record; 
   type Element_type_A_Access is access all Element_type_A'Class;   
   overriding function Report(This : Element_Type_A ) return Intro.state is ( Intro.KO);
   function Get_Values (this : Element_type_A ) return SomeData'Class is
      (this.data);

   
   -- ELEMENT B   
   type OtherData is new Intro.Data_type with record 
     a :float; 
   end record; 

   package Readable_Other is new Intro.Readable( 
      readable_data =>OtherData); 
   package Reporting_Other is new Intro.Reporting(Readable_Other); 

   type Element_type_B is new Readable_Other.Readable_Element 
                                     and Reporting_Other.Reporting_Element 
   with record 
      data :OtherData; 
   end record;   
   type Element_type_B_Access is access all Element_type_B'Class; 
   function Get_Values (this : Element_type_B ) return OtherData'Class is
      (this.data);
   function Report(This : Element_type_B ) return Intro.state is ( Intro.KO);
   
   --MANAGER --
   package Readable_basic is new Intro.Readable(Intro.Data_type ); 
   package Reporting_basic is new Intro.Reporting(Readable_basic);
   use Reporting_basic;

    package Element_Vector is new
       Ada.Containers.Vectors (Natural,Reporting_basic.Reporting_Element_Access);
     use Element_Vector;
   
   type Manager is tagged record  
     elements :  Element_Vector.Vector;
   end record;
   procedure Add_Element(this : in out Manager ;
                         Element : in Reporting_Element_Access ) is
   begin
      this.elements.Append(Element);
   end Add_Element;
   
   Man : Manager;
   Elm1_ptr : Element_type_A_Access := new Element_type_A;
   Elm2_ptr : Element_type_B_Access := new Element_type_B;
begin  
   Add_Element(Man,Reporting_basic.Reporting_Element_Access(Elm1_ptr));
   Add_Element(Man,Reporting_basic.Reporting_Element_Access(Elm2_ptr));
   put_Line("hello world");
   
end test;

The problem might be in how I am instancing the generic for manager (readable_basic and reporting_basic), but I can't use a box association or unconstrained type in there.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: working with diferent instances of the same generic interface
  2015-09-09 11:08   ` Aitor Alcrudo Sangros
@ 2015-09-09 12:17     ` Egil H H
  2015-09-09 12:41       ` Aitor Alcrudo Sangros
  2015-09-10 12:22     ` Jacob Sparre Andersen
  1 sibling, 1 reply; 16+ messages in thread
From: Egil H H @ 2015-09-09 12:17 UTC (permalink / raw)


On Wednesday, September 9, 2015 at 1:08:51 PM UTC+2, Aitor Alcrudo Sangros wrote:
<snip>

Reporting_basic.Reporting_Element_Access is an access type that can 
only point to variables of type Reporting_basic.Reporting_Element.

Element_type_A_Access is an access type that can
only point to variables of type Element_type_A 
(which derives from Reporting_some.Reporting_Element)

Reporting_some.Reporting_Element and Reporting_basic.Reporting_Element
are two different types. Converting between them (or access to them) 
would be like trying to convert a giraffe into an elephant.


-- 
~egilhh

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: working with diferent instances of the same generic interface
  2015-09-09 12:17     ` Egil H H
@ 2015-09-09 12:41       ` Aitor Alcrudo Sangros
  2015-09-09 13:10         ` Egil H H
  0 siblings, 1 reply; 16+ messages in thread
From: Aitor Alcrudo Sangros @ 2015-09-09 12:41 UTC (permalink / raw)


El miércoles, 9 de septiembre de 2015, 14:17:52 (UTC+2), Egil H H  escribió:
> On Wednesday, September 9, 2015 at 1:08:51 PM UTC+2, Aitor Alcrudo Sangros wrote:
> <snip>
> 
> Reporting_basic.Reporting_Element_Access is an access type that can 
> only point to variables of type Reporting_basic.Reporting_Element.
> 
> Element_type_A_Access is an access type that can
> only point to variables of type Element_type_A 
> (which derives from Reporting_some.Reporting_Element)
> 
> Reporting_some.Reporting_Element and Reporting_basic.Reporting_Element
> are two different types. Converting between them (or access to them) 
> would be like trying to convert a giraffe into an elephant.
> 
> 
> -- 
> ~egilhh

Well they instance the same generic interface so more like trying to turn a dog into a coyote, but that's why I'm asking for help.

There should be a way to make Manager be able to work with objects of different instances of the generic Reporting_Element interface. The class Manager does not need to know the internals of any of those instances just that they implement some functions and procedures that can be called.

I am trying to determine if this is at all possible and how should I go about it. From what I know of Ada and other languages I think it should be doable so I'm trying to find the correct way.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: working with diferent instances of the same generic interface
  2015-09-09 12:41       ` Aitor Alcrudo Sangros
@ 2015-09-09 13:10         ` Egil H H
  2015-09-09 14:50           ` Aitor Alcrudo Sangros
  0 siblings, 1 reply; 16+ messages in thread
From: Egil H H @ 2015-09-09 13:10 UTC (permalink / raw)


On Wednesday, September 9, 2015 at 2:41:03 PM UTC+2, Aitor Alcrudo Sangros wrote:
> 
> Well they instance the same generic interface so more like trying to turn a dog into a coyote, but that's why I'm asking for help.

It doesn't matter that they are defined in instances of the same generic,
they are completely different types, with no common ancestor, just like:

type Foo is interface;
type Bar is interface;

Would you say converting Foo into Bar is like turning a dog into a coyote?

-- 
~egilhh

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: working with diferent instances of the same generic interface
  2015-09-09 13:10         ` Egil H H
@ 2015-09-09 14:50           ` Aitor Alcrudo Sangros
  2015-09-09 16:48             ` Egil H H
  2015-09-13 18:22             ` Florian Weimer
  0 siblings, 2 replies; 16+ messages in thread
From: Aitor Alcrudo Sangros @ 2015-09-09 14:50 UTC (permalink / raw)


El miércoles, 9 de septiembre de 2015, 15:10:08 (UTC+2), Egil H H  escribió:
> On Wednesday, September 9, 2015 at 2:41:03 PM UTC+2, Aitor Alcrudo Sangros wrote:
> > 
> > Well they instance the same generic interface so more like trying to turn a dog into a coyote, but that's why I'm asking for help.
> 
> It doesn't matter that they are defined in instances of the same generic,
> they are completely different types, with no common ancestor, just like:
> 
> type Foo is interface;
> type Bar is interface;
> 
> Would you say converting Foo into Bar is like turning a dog into a coyote?
> 
> -- 
> ~egilhh

Ok, so you are saying I can't treat two instances of an interface the same way even if the only thing I want is to call interface procedures/functions?

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: working with diferent instances of the same generic interface
  2015-09-09 14:50           ` Aitor Alcrudo Sangros
@ 2015-09-09 16:48             ` Egil H H
  2015-09-09 19:04               ` Aitor Alcrudo Sangros
  2015-09-13 18:22             ` Florian Weimer
  1 sibling, 1 reply; 16+ messages in thread
From: Egil H H @ 2015-09-09 16:48 UTC (permalink / raw)


No, I am saying you have two different interfaces.
Conceptually, you can think of generic instances as copies 
of the source text. So being inside a generic makes them 
different because the generic is instantiated twice.

-- 
~egilhh


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: working with diferent instances of the same generic interface
  2015-09-09 16:48             ` Egil H H
@ 2015-09-09 19:04               ` Aitor Alcrudo Sangros
  2015-09-09 19:16                 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 16+ messages in thread
From: Aitor Alcrudo Sangros @ 2015-09-09 19:04 UTC (permalink / raw)


On Wednesday, September 9, 2015 at 6:48:35 PM UTC+2, Egil H H wrote:
> No, I am saying you have two different interfaces.
> Conceptually, you can think of generic instances as copies 
> of the source text. So being inside a generic makes them 
> different because the generic is instantiated twice.
> 
> -- 
> ~egilhh

Well, I still can't do what I wanted so that's a little disappointing.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: working with diferent instances of the same generic interface
  2015-09-09 19:04               ` Aitor Alcrudo Sangros
@ 2015-09-09 19:16                 ` Dmitry A. Kazakov
  2015-10-01 16:45                   ` Aitor Alcrudo Sangros
  0 siblings, 1 reply; 16+ messages in thread
From: Dmitry A. Kazakov @ 2015-09-09 19:16 UTC (permalink / raw)


On Wed, 9 Sep 2015 12:04:42 -0700 (PDT), Aitor Alcrudo Sangros wrote:

> Well, I still can't do what I wanted so that's a little disappointing.

You didn't say what you wanted to do and why you wanted that.

P.S. Interfaces are actually for getting rid of generics...

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: working with diferent instances of the same generic interface
  2015-09-09 11:08   ` Aitor Alcrudo Sangros
  2015-09-09 12:17     ` Egil H H
@ 2015-09-10 12:22     ` Jacob Sparre Andersen
  1 sibling, 0 replies; 16+ messages in thread
From: Jacob Sparre Andersen @ 2015-09-10 12:22 UTC (permalink / raw)


Aitor Alcrudo Sangros wrote:

> Hi, I'm not really specifically tring to make that code work as
> is. What I want to know is how can I work with different instances of
> the same generic interface, doing things like iterating over a
> collection of them. This is a minimal example of how I am
> (unsuccessfully ) tring to do so. Anyway this code compiles, then has
> a runtime exception.

Your problem is that you instantiate the same package much too often.
Here is a working "solution":

package Intro is
      type Data_type is interface;

      generic
         type Readable_Data is abstract new Data_type with private;
      package Readable is
         type    Readable_Element is interface;
         subtype Readable_Class   is Readable_Element'Class ;
         function Get_Values (this : Readable_Element ) return Readable_Data'Class
                           is abstract;
      end Readable;

      type state is (OK,KO);

      generic
         with package Readable_Reporting is new Readable(<>);
         use Readable_Reporting ;
      package Reporting is
         type    Reporting_Element is interface and Readable_Element ;
         subtype Reporting_Class   is Reporting_Element'Class;
         function Report (This :Reporting_Element  ) return state is Abstract;
         overriding function Get_Values (this : Reporting_Element ) return
           Readable_Data'Class is abstract;
      end Reporting;
   end Intro;
with Intro;

package Instantiations is
   package Readable_Basic  is new Intro.Readable  (Intro.Data_Type);
   package Reporting_Basic is new Intro.Reporting (Readable_Basic);
end Instantiations;
with Intro,
     Instantiations;

package A is
   type SomeData is new Intro.Data_type with record
      a :float;
   end record;

   package Readable_Some  renames Instantiations.Readable_Basic;
   package Reporting_Some renames Instantiations.Reporting_Basic;

   type Element_type_A is
     new Readable_Some.Readable_Element and Reporting_Some.Reporting_Element
     with
      record
         data : SomeData := SomeData'(a => 0.0 );
      end record;

   subtype Element_type_A_Class is Element_type_A'Class;
   overriding function Report(This : Element_Type_A ) return Intro.state is ( Intro.KO);

   overriding
   function Get_Values (this : Element_type_A ) return Intro.Data_Type'Class is
      (this.data);
end A;
with Intro,
     Instantiations;

package B is
   type OtherData is new Intro.Data_type with record
      a :float;
   end record;

   package Readable_Other  renames Instantiations.Readable_Basic;
   package Reporting_Other renames Instantiations.Reporting_Basic;

   type Element_type_B is new Readable_Other.Readable_Element
     and Reporting_Other.Reporting_Element
     with record
        data :OtherData;
   end record;
   subtype Element_type_B_Class is Element_type_B'Class;
   function Get_Values (this : Element_type_B ) return Intro.Data_Type'Class is
      (this.data);
      function Report(This : Element_type_B ) return Intro.state is ( Intro.KO);
end B;
with Ada.Containers.Indefinite_Vectors;

with Intro,
     Instantiations;

package Manager is
   package Reporting_Basic renames Instantiations.Reporting_Basic;
   use Reporting_Basic;

   package Element_Vector is new
     Ada.Containers.Indefinite_Vectors
     (Index_Type   => Natural,
      Element_Type => Reporting_Basic.Reporting_Class);
   use Element_Vector;

   type Manager is tagged record
      elements :  Element_Vector.Vector;
   end record;
   procedure Add_Element(this : in out Manager ;
                         Element : in Reporting_Class );
end Manager;

   package body Manager is
      procedure Add_Element(this : in out Manager ;
                            Element : in Reporting_Class ) is
      begin
         this.elements.Append(Element);
      end Add_Element;
   end Manager;
with Ada.Text_IO;

with A, B, Manager;

procedure Test is
   Man      : Manager.Manager;
   Elm1_ptr : A.Element_Type_A_Class := A.Element_Type_A'(Data => (A => 1.0));
   Elm2_ptr : B.Element_Type_B_Class := B.Element_Type_B'(Data => (A => 2.0));
begin
   Man.Add_Element (Manager.Reporting_basic.Reporting_Class(Elm1_ptr));
   Ada.Text_IO.Put_Line ("1 worked.");

   Man.Add_Element (Manager.Reporting_basic.Reporting_Class(Elm2_ptr));
   Ada.Text_IO.Put_Line ("2 worked.");
end Test;

Notice how there's no need for access types.

Greetings,

Jacob
-- 
"Universities are not part of the nation's security organisation,
 they are not the nation's research laboratory either: they are
 the nation's universities."                     -- E.W. Dijkstra

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: working with diferent instances of the same generic interface
  2015-09-09 14:50           ` Aitor Alcrudo Sangros
  2015-09-09 16:48             ` Egil H H
@ 2015-09-13 18:22             ` Florian Weimer
  1 sibling, 0 replies; 16+ messages in thread
From: Florian Weimer @ 2015-09-13 18:22 UTC (permalink / raw)


* Aitor Alcrudo Sangros:

> Ok, so you are saying I can't treat two instances of an interface the
> same way even if the only thing I want is to call interface
> procedures/functions?

You'd have to define the interface outside the generic package, so
that it is not generic.

Alternatively, you can write another generic which takes the instance
as a generic formal argument.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: working with diferent instances of the same generic interface
  2015-09-09 19:16                 ` Dmitry A. Kazakov
@ 2015-10-01 16:45                   ` Aitor Alcrudo Sangros
  2015-10-01 19:29                     ` Dmitry A. Kazakov
  0 siblings, 1 reply; 16+ messages in thread
From: Aitor Alcrudo Sangros @ 2015-10-01 16:45 UTC (permalink / raw)


On Wednesday, September 9, 2015 at 9:16:13 PM UTC+2, Dmitry A. Kazakov wrote:
> On Wed, 9 Sep 2015 12:04:42 -0700 (PDT), Aitor Alcrudo Sangros wrote:
> 
> > Well, I still can't do what I wanted so that's a little disappointing.
> 
> You didn't say what you wanted to do and why you wanted that.
> 
> P.S. Interfaces are actually for getting rid of generics...
> 
> -- 
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de

Hi, Sorry for the late answer, I badly hurt my back, and had to minimize my computer usage for a while. I wanted to know if I could just do that ( use diferent instances of a generic interface as if they had a common base type). The larger point I was tring to solve could be solved using non-generic interfaces without a hitch. Just that the first solution that popped in my mind included the generic parameter and wanted to know if it could be done. Anyway thanks a lot for the responses. 

 


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: working with diferent instances of the same generic interface
  2015-10-01 16:45                   ` Aitor Alcrudo Sangros
@ 2015-10-01 19:29                     ` Dmitry A. Kazakov
  2015-10-01 20:09                       ` Randy Brukardt
  0 siblings, 1 reply; 16+ messages in thread
From: Dmitry A. Kazakov @ 2015-10-01 19:29 UTC (permalink / raw)


On Thu, 1 Oct 2015 09:45:46 -0700 (PDT), Aitor Alcrudo Sangros wrote:

> I wanted to know if I could just do that ( use diferent instances of a
> generic interface as if they had a common base type).

"generic interface" means

1. a way to use a generic unit (to interface it) = not a type

2. a type, specifically an interface type declared within a generic unit.

Considering #2 two interfaces have nothing in common unless they explicitly
have a common base. It was already mentioned that the base can be a generic
formal parameter, but it must be the same actual type to make instances
from the generic related.

> Just that the first solution that popped in my mind included the
> generic parameter and wanted to know if it could be done. 

Parameter is no problem.

There is no magic in generics (except for making programs unmaintainable).
Consider each generic instance as a manually re-typed unit and then apply
Ada rules to the result.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: working with diferent instances of the same generic interface
  2015-10-01 19:29                     ` Dmitry A. Kazakov
@ 2015-10-01 20:09                       ` Randy Brukardt
  0 siblings, 0 replies; 16+ messages in thread
From: Randy Brukardt @ 2015-10-01 20:09 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
news:1qdvz5nsrt3yp.gmtykg9khnkm$.dlg@40tude.net...
...
> There is no magic in generics (except for making programs unmaintainable).
> Consider each generic instance as a manually re-typed unit and then apply
> Ada rules to the result.

That's not 100% true (the way exceptions declared in generic bodies are 
handled comes to mind), but it's close enough for almost all purposes. You'd 
have to be a language lawyer to care about the differences (I plead guilty 
to that :-).

                              Randy.



^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2015-10-01 20:09 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-08 15:10 working with diferent instances of the same generic interface Aitor Alcrudo Sangros
2015-09-08 17:11 ` G.B.
2015-09-09  6:38 ` Jacob Sparre Andersen
2015-09-09 11:08   ` Aitor Alcrudo Sangros
2015-09-09 12:17     ` Egil H H
2015-09-09 12:41       ` Aitor Alcrudo Sangros
2015-09-09 13:10         ` Egil H H
2015-09-09 14:50           ` Aitor Alcrudo Sangros
2015-09-09 16:48             ` Egil H H
2015-09-09 19:04               ` Aitor Alcrudo Sangros
2015-09-09 19:16                 ` Dmitry A. Kazakov
2015-10-01 16:45                   ` Aitor Alcrudo Sangros
2015-10-01 19:29                     ` Dmitry A. Kazakov
2015-10-01 20:09                       ` Randy Brukardt
2015-09-13 18:22             ` Florian Weimer
2015-09-10 12:22     ` Jacob Sparre Andersen

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