Ada-Rapporteur-Group / User-Community-Input

Ada User Community Input Working Group - Github Mirror Prototype
27 stars 1 forks source link

Would like to be able to specify that a parameter should implement multiple interfaces #16

Open sttaft opened 2 years ago

sttaft commented 2 years ago

Ada Language: There's currently no way to specify that a subprogram parameter should implement more than one interface.


I can see possible solutions: 1) allow syntax like this:

procedure Do_Something (Object : in Interface_1 and Interface_2);

This would means that an object passed to Do_Something would have to implement both interfaces. Currently we can (arbitrarily) choose one and internally cast to the other as needed, but we can't specify in the definition of the subprogram that it expects both to be implemented by the parameter.

If the object implements these interfaces (or descendants of these interfaces) we can't pass it to a subprogram expecting both unless we also define a new interface that includes both, and change the definition of the object type to (redundantly) also implement that new interface.

Allowing this sort of anonymous interface type would solve that problem, and we could pass the object in without having to both define a new interface and change the definition of an existing type to include a new interface that only includes parts that were already part of the type.

2) allow interface subtypes that would work something like this:

subtype Interface_1_And_2 is interface and Interface_1 and Interface_2;

procedure Do_Something (Object : Interface_1_and_2);

In this case, any object that implements Interface_1 and Interface_2, or descendants thereof could be passed to Do_Something. They wouldn't need to explicitly implement Interface_1_And_2, since they already implement both of those.

Joshua Fletcher, fletcher.ua@gmail.com, 7/14/2022 15:29:24