Skip to content

[RFC] Deferred Partial Instantiation of Generic Specifications #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

jere-software
Copy link

@jere-software jere-software commented Apr 4, 2020

Link to text: https://github.com/jeremiahbreeden/ada-spark-rfcs/blob/topic/deferred_partial_instantiation/considered/rfc-deferred-partial-instantiation.rst

This is to suggest providing a means of creating a simpler specification of a generic by allowing some parameters of the generic to be specified manually while leaving the rest to the client instantiator. In short it allows for specification:

    generic
       type Type1 is private;
       type Type2 is limited private;
       type Type3(<>);
       with procedure Something(Param1 : Type2; Param2 : Type3);
       with function Image(Value : Type1) return String;
    package My_Package is
       procedure Yay(Value : Type1);  -- calls Image internally
       -- Other Stuff
    end My_Package;

to be simplified (notionally) in a later generic:

    generic
       type Type1 is private;
       with function Image(Value : Type1) return String;
    package My_Client_Package is
       -- Same public API as before
    end My_Client_Package;

using the syntax:

    generic
       type Type1 is private;
       with function Image(Value : Type1) return String;
    package My_Client_Package is new My_Package
       (Type1     => Type1,
        Type2     => Integer,
        Type3     => String,
        Something => Something_For_Integer_And_String,
        Image     => Image);

without needing to provide scaffolding or package chaining.

@sttaft
Copy link
Contributor

sttaft commented Apr 14, 2020

Nice proposal. Need to decide how this interacts with formal packages. In particular, would any instance of the original generic package that matched the partial instantiation be considered an instance of this new generic, and similarly, would any instance of this new generic be considered an instance of the original generic?

@jere-software
Copy link
Author

@sttaft Thanks. I tried updating the proposal with how to handle it. I marked it as OPTIONAL. If it makes the proposal untenable, then it could easily be pulled back out and we could just consider them separate generic package specifications, but I would like to at least explore allowing them to be used interchangeably (with respect to the formal values supplied). I will say I am getting into a realm where I am not 100% good with the terminology so suggestions on how to fix any of it are appreciated. Hopefully it at least can be deciphered from the examples if I botched the wording.

@sttaft
Copy link
Contributor

sttaft commented Apr 14, 2020 via email

@mosteo
Copy link

mosteo commented Apr 15, 2020

I have wanted so much this when working on my Rx and Iterators libraries.

About the extra level of indirection: this already happens sometimes with package renamings, so it's not an entirely new nuisance.

@raph-amiard raph-amiard added RFC enhancement New feature or request generics labels Jun 18, 2020
@briot
Copy link

briot commented Mar 6, 2023

I had missed that proposal, and saw it mentioned in https://github.com/AdaCore/ada-spark-rfcs/blob/topic/generic_instantiations/meta/rfc-improved-generic-instantiations.md

I also very much like this approach, and indeed missed it when working on the traits-containers library

@jere-software
Copy link
Author

Thanks! I honestly thought this just got lost in the wind. Glad it can still poke its head around. Maybe one day we'll have something similar to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request generics RFC
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants