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

[Feature] Add an array generic type #391

Closed
Ph0enixKM opened this issue Aug 6, 2024 · 6 comments · Fixed by #472
Closed

[Feature] Add an array generic type #391

Ph0enixKM opened this issue Aug 6, 2024 · 6 comments · Fixed by #472
Assignees
Labels
enhancement New feature or request

Comments

@Ph0enixKM
Copy link
Member

Is your feature request related to a problem? Please describe.
The problem is that sometimes a person might want to match any Array type when declaring a function parameter.

fun len(array: []): Num {
    ...
}

Describe the solution you'd like

  • Add the [] syntax in Types
  • Handle the [] type only in function parameter types.

Describe alternatives you've considered
I've considered function overloading but it seems to be an overkill.

Additional context
This way we can more precisely specify the context and use of functions.

@Ph0enixKM Ph0enixKM added the enhancement New feature or request label Aug 6, 2024
@b1ek
Copy link
Member

b1ek commented Aug 8, 2024

what about adding explicit Any type and every time you need to put a generic type anywhere you just use Any? (including arrays)

@Ph0enixKM
Copy link
Member Author

Yeah.. I've been thinking about this... if this is a good idea to introduce such type. TypeScript has done it because JS enforced it. Aaaand... in any real project you're advised not to use it. So this was a proposition that would not lead people to bad patterns. If you want to use Any type - then just don't specify any type. What do you think?

@Ph0enixKM
Copy link
Member Author

How about we add generics instead.

fn foo<T>(array: [T]) {

}

@Ph0enixKM Ph0enixKM changed the title [Feature] Add an array generic type [] [Feature] Add an array generic type Aug 8, 2024
@mks-h
Copy link
Member

mks-h commented Sep 2, 2024

I'd start with the generic array, as it is simpler to implement and to use. Also we don't have to limit it to parameters, it might be useful as a return type, too.

Then, later on, we can extend this syntax to also allow named generics such as fn first<T>(arr: [T]): T. Except I'd also look for a better syntax that won't require defining them before using, like fn first(arr: ['T]): 'T.

@mks-h mks-h self-assigned this Sep 3, 2024
@KrosFire
Copy link
Member

KrosFire commented Sep 3, 2024

I'd start with the generic array, as it is simpler to implement and to use. Also we don't have to limit it to parameters, it might be useful as a return type, too.

Then, later on, we can extend this syntax to also allow named generics such as fn first<T>(arr: [T]): T. Except I'd also look for a better syntax that won't require defining them before using, like fn first(arr: ['T]): 'T.

I like this 'T syntax

@Ph0enixKM
Copy link
Member Author

I love that idea of 'T syntax @mks-h ! Great job!

@Ph0enixKM Ph0enixKM linked a pull request Sep 12, 2024 that will close this issue
@Mte90 Mte90 closed this as completed in #472 Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants