feat: Allow numeric generics to be referenced and add map
#997
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related issue(s)
Resolves #972
Description
Summary of changes
Allows numeric generics to be referenced like normal values. This resolves a common stumbling block for users when writing a function like the following:
Previously, we would error that there is no
N
in scope (sinceN
is a type and not a value). With this PR, this code works as expected.Notably, this PR now allows us to write the array
map
function and add it to our stdlib. This was not possible previously due to the syntax limitations placed on array-length expressions which prevented us from initializing an array usinglet mut ret = [0; array.len()];
. This has been reworked slightly to reuse the same array length evaluation mechanism types use, which notably now allows us to use numeric generic type variables.Dependency additions / changes
Test additions / changes
Added a test for the new array
map
function inhigher_order_functions
.Checklist
cargo fmt
with default settings.Documentation needs
We should document numeric generics are now useable like any other
Field
variable. Additionally, the newmap
method for arrays will need to be documented.