Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8191723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:58:49+00:00 2026-06-07T03:58:49+00:00

The declaration of generic parameters is not exhaustive enough to give type relationships (subtypes)

  • 0

The declaration of generic parameters is not exhaustive enough to give type relationships (subtypes) and this information is simply lost… For example :

-- generic_p.ads
generic
   type Index_Range_Type is range <>;
   type Count_Range_Type is range <>;
procedure Generic_P (I : Index_Range_Type, C : Count_Range_Type);

-- generic_p.adb
procedure Generic_P (I : Index_Range_Type, C : Count_Range_Type) is
begin
   if I = C then -- oops : cannot compare different types...
     -- ...
   end if;
end Generic_P;

-- main.adb
procedure Main is
   type Index_Range_Type is 0 .. 512;
   subtype Count_Range_Type is Index_Range_Type range 1 .. Index_Range_Type'Last;

   procedure P is new Generic_P (Index_Range_Type, Count_Range_Type);

   I : Index_Range_Type := 33;
   C : Count_Range_Type := 42;
begin
   if I = C then -- Ok : Count_Range is a subset of Index_Range, they can be compared
      -- ...
   end if;
   P (I, C);
end Main;

Which gives the following error for the comparison in generic_p.adb : invalid operand types [...] left operand has type "Index_Range_Type" [...] right operand has "type Count_Range_Type". The subtyping is not visible in the generic procedure.

Is there any way to specify the relationship between generic parameters ?

Further Informations

I really need Count_Range_Type as a parameter of the procedure to be able to add another parameter which needs Count_Range_Type.

-- generic_p.ads
generic
   type Index_Range_Type is range <>;
   type Count_Range_Type is range <>;
   with procedure F (C : Count_Range_Type);
procedure Generic_P (I : Index_Range_Type, C : Count_Range_Type);

I can’t directly use the type, I need P to be absolutely generic and independent.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T03:58:50+00:00Added an answer on June 7, 2026 at 3:58 am

    This addresses the “Further Informations” portion of the original question, whereby a generic needs to be instantiated with a procedure containing a parameter that’s a subtype of the instantiating type.

    Essentially, a generic package is employed to set up the subtype, and then a generic child package provides the desired procedure (which is instantiated with the generic formal procedure). Admittedly, this is a rather involved solution to the problem. So here we go:

    The “parent” generic that creates the subtype:

    generic
       type Index_Range_Type is range <>;
    package Generic_Provider is
       pragma Assert(Index_Range_Type'First = 0);
       subtype Count_Range_Type is Index_Range_Type range 1 .. Index_Range_Type'last;
    
    end Generic_Provider;
    

    All this does is declare the subtype, it needs no body (and in fact a body would be illegal).

    Here’s the spec of our procedure provider, which utilizes a client-supplied formal procedure.

    generic
       with procedure F(I : Index_Range_Type;
                        C : Count_Range_Type);
    
    package Generic_Provider.Services is
    
       procedure P (I : Index_Range_Type; C : Count_Range_Type);
    
    end Generic_Provider.Services;
    

    Just for grins, its body, which verifies that the formal procedure can be invoked and that the subtype comparison is valid:

    package body Generic_Provider.Services is
    
       procedure P (I : Index_Range_Type; C : Count_Range_Type) is
       begin
          if I = C then
             F(I, C);
          end if;
       end P;
    
    end Generic_Provider.Services;
    

    Finally, the instantiating main program:

    with Generic_Provider.Services;
    
    procedure Main is
       type Index_Range_Type is range 0 .. 512;
       package Type_Provider is new Generic_Provider (Index_Range_Type);
       subtype Count_Range_Type is Type_Provider.Count_Range_Type;
    
       procedure My_F (I : Index_Range_Type;
                       C : Count_Range_Type) is
       begin
          null;
       end My_F;
    
       package P_Provider is new Type_Provider.Services(My_F);
    
       I : Index_Range_Type := 33;
       C : Count_Range_Type := 42;
    begin
       if I = C then
          null;
       end if;
       P_Provider.P (I, C);
    end Main;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As discussed here , C# doesn't support generic attribute declaration. So, I'm not allowed
I created some methods that use nested type parameters generic types in the parameter
Is there any (technical) reason that C# requires all generic type parameters to be
Consider this declaration with generics: public class BaseNode<TNode> where TNode : BaseNode<TNode> { public
declaration of textfield1 <td nowrap=nowrap><input type=text name=textfield1 id=textfield1/></td> trying to return the value entered
Declaration: I am not sure if that is a parameter. Please enlighten. I have
This is the properties declaration: @property (atomic, weak) zooView* zooView; This is my custom
I'm trying to implement in Scala a generic data type parameterized on a type
Consider the following declaration of a generic utility class in Delphi 2010: TEnumerableUtils =
What generic type should i use, if I have to assign a Character value

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.