Generic type/function parameters over values #3550
Shad0wRim
started this conversation in
Ideas & suggestions
Replies: 1 comment 9 replies
-
Hello! Could you expand on what real-world problems and pain points this feature would solve for Gleam users please? The concrete benefits of adding this feature are not very clear to me yet. Thanks! |
Beta Was this translation helpful? Give feedback.
9 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In Rust, there are const generics that allow a type to be generic over a value rather than a type:
I would love something like this to be put into gleam, using perhaps using
const
like rust or just by specifying the type of the parameter in the type parameter.Instantiating this type would require a type hint, as I am unsure how it could be specified in the constructor if it is used as a "phantom" parameter.
Perhaps if the type parameter name shares the same name and type as one of the fields in the record, the type hint could be removed, but the corresponding field would have to be known at compile time.
Functions that use this type could extract the const type parameter with similar syntax to current generics
Would love some feedback on this, and would love something like this as I ran into an issue where I couldn't create a type representing the rationals adjunct square_root(n) without creating a separate type for each n or supplying the n to each function call, making the calls not type-safe.
Beta Was this translation helpful? Give feedback.
All reactions