-
Notifications
You must be signed in to change notification settings - Fork 23
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
RFC: Variadic Generics #362
Comments
This issue have two parts:
For point 1, there are several existing methods that you can try to explore - you can emulate the list of types as a single tuple type param. Then you'll be able to use some easily added magics to the For point 2, the currently supported way is to rely on a macro that will accept the params and directly handle them or repackage them as a tuple that will be passed to a generic proc. In the manual, you'll find an example for a A small task on my to-do list is to automate this repackaging as a tuple in order to let you write more easily such generic procs with heterogeneous varargs. |
$50 bounty has been posted on this issue https://www.bountysource.com/issues/1446763-rfc-variadic-generics. Thanks @Henry |
@dom96 : No problem, I like the idea of BountySource and wanted to get the ball rolling. I am migrating from Xl2 to Nim and in Xl2 variadic generics are a fundamental part of the design being used for multi-argument, multi-type write functions and I rather like this appoach. There is an example on https://en.wikipedia.org/wiki/XL_(programming_language) and examples provided:
While this example shows all the arguments of the same type they need not be as in the Write and WriteLn library functions:
Maybe studying the implementation of variadic generics in the xl2 compiler will help. |
As far as syntax goes, why not simply reuse the |
The examples are all trivially implementable with a macro and/or varargs[T, conv]. |
@Araq but there are still things like matrices and other areas that would benefit from variadic generic types. |
It should be easy enough to use tuples and the getType API in these cases though. Somebody needs to write this code and demonstrate what problems it causes. |
@Araq, does your method allow for taking a variable number of template parameter constants (say, ints) and generating an array of function pointers from a template function with them? E.g. in C++:
Pardon me if it's obvious to do this with compile time functions in Nim, but I'm curious, because this sort of pattern heavily simplifies metaprogramming for me. |
variadic generics would help the |
The benefits are tiny, Nim has tuples, you can pass a tuple to thread proc. |
As far as I can tell Nimrod does not support any kind of variadic generic. That is a generic procedure that can take 0 or more type arguments.
The motivation for this is for functions like printf where you would like to have a variadic function where each one of the variadic parameters has a different type. The varargs feature does not do this.
Both c++ and D implement variadic generics in such a way where a parameter of type T... can be zero or more types and it can be decomposed into T1, Rest... in a parameter list.
For reference both c++ and D support this feature
http://dlang.org/variadic-function-templates.html
Variadic Templates, section 14.5.3 of the latest c++ draft standard (n3242)
Rust has a ticket open for this at: rust-lang/rust#10124
The text was updated successfully, but these errors were encountered: