IssueRaiser

Draft RFC: variadic generics

<a href="https://github.com/eddyb"><img src="https://avatars.githubusercontent.com/u/77424?v=2" align="left" width="96" height="96" hspace="10"></img></a> **Issue by [eddyb](https://github.com/eddyb)** _Monday Oct 28, 2013 at 17:39 GMT_ _For earlier discussion, see https://github.com/rust-lang/rust/issues/10124_ _This issue was labelled with: B-RFC in the Rust repository_ --- ## The Problem - [fn types need a reform](http://smallcultfollowing.com/babysteps/blog/2013/10/10/fn-types-in-rust/), and being able to define a trait with a variable number of type parameters would help - working with functions which have a variable number of arguments is impossible right now (e.g. a generic `bind` method, `f.bind(a, b)(c) == f(a, b, c)`) and defining such functions may only be done (in a limited fashion) with macros - tuples also have similar restrictions right now, there is no way to define a function which takes any tuple and returns the first element, for example ## The Solution: Part One C++11 sets a decent precedent, with its variadic templates, which can be used to define type-safe variadic functions, among other things. I propose a similar syntax, a trailing `..T` in generic formal type parameters: ``` rust type Tuple<..T> = (..T); // the parens here are the same as the ones around a tuple. // use => expansion Tuple<> => () Tuple<int> => (int,) Tuple<A, B, C> => (A, B, C) ``` The simple example above only uses `..T`, but not `T` itself. The question which arises is this: w

Posted by rust-highfive on Oct 8, 2014, 11:34 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.9,000 issues0 comments

github (Software)

Draft RFC: variadic generics

rust-highfiveOct 8, 2014, 11:34 PM

<a href="https://github.com/eddyb"><img src="https://avatars.githubusercontent.com/u/77424?v=2" align="left" width="96" height="96" hspace="10"></img></a> **Issue by [eddyb](https://github.com/eddyb)** _Monday Oct 28, 2013 at 17:39 GMT_ _For earlier discussion, see https://github.com/rust-lang/rust/issues/10124_ _This issue was labelled with: B-RFC in the Rust repository_ --- ## The Problem - [fn types need a reform](http://smallcultfollowing.com/babysteps/blog/2013/10/10/fn-types-in-rust/), and being able to define a trait with a variable number of type parameters would help - working with functions which have a variable number of arguments is impossible right now (e.g. a generic `bind` method, `f.bind(a, b)(c) == f(a, b, c)`) and defining such functions may only be done (in a limited fashion) with macros - tuples also have similar restrictions right now, there is no way to define a function which takes any tuple and returns the first element, for example ## The Solution: Part One C++11 sets a decent precedent, with its variadic templates, which can be used to define type-safe variadic functions, among other things. I propose a similar syntax, a trailing `..T` in generic formal type parameters: ``` rust type Tuple<..T> = (..T); // the parens here are the same as the ones around a tuple. // use => expansion Tuple<> => () Tuple<int> => (int,) Tuple<A, B, C> => (A, B, C) ``` The simple example above only uses `..T`, but not `T` itself. The question which arises is this: w

Comments (0)

No comments yet. Start the discussion.

Comment on this issue