Skip to content
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

order-independent parameters when referencing each other #3226

Open
anthonyquizon opened this issue Sep 13, 2019 · 1 comment
Open

order-independent parameters when referencing each other #3226

anthonyquizon opened this issue Sep 13, 2019 · 1 comment
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@anthonyquizon
Copy link

Eg. A function like this doesn't compile:

fn Module(comptime T: type) type {                                                                                                                                                                                 
    const ListType = ArrayList(T);                                                                                                                                                                                 
                                                                                                                                                                                                                   
    return struct {                                                                                                                                                                                                
        pub fn reduce(
            f: fn(T, @typeOf(init)) @typeOf(init), 
            init: var, 
            list: ListType
        ) @typeOf(init)  {                                                                                                            
        //  ...                                                                                                                                                                                      
        }                                                                                                                                                                                                          
    };                                                                                                                                                                                                             
}     

Where init is ordered before f but is referenced by f with @typeOf.

However, if init is placed at the start of the function, it is able to be referenced

        // ...
        pub fn reduce(
            init: var, 
            f: fn(T, @typeOf(init)) @typeOf(init), 
            list: ListType
        ) @typeOf(init) {                                                                                                            
        //  ...                                                                                                                                                                                      
        }       

I would have thought that @typeOf should be able to reference an argument regardless of order.

@andrewrk andrewrk added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Sep 16, 2019
@andrewrk andrewrk added this to the 0.6.0 milestone Sep 16, 2019
@andrewrk andrewrk changed the title @typeOf references depends on function argument order order-independent parameters when referencing each other Sep 16, 2019
@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Feb 13, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 27, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 May 19, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 Nov 23, 2021
@andrewrk andrewrk modified the milestones: 0.10.0, 0.11.0 Apr 16, 2022
@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Apr 9, 2023
@wooster0
Copy link
Contributor

wooster0 commented Apr 23, 2023

Yes, I think it'd be great if parameters could just be order-independent like top-level declarations. I think it'd make things like #4437 easier too.

I just think that implementing this may or may not be a requirement for if we want to really allow people to design their APIs the way they want. Having to have parameters be in a certain order just for technical reasons rather than actually thinking that's a good order is not something that's very good I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

3 participants