Some of these partial application syntax proposals are approaching https://www.boost.org/libs/lambda, which added lambdas to C++ as a library. For example, one could do _1 * 2
for what rust calls |x| x * 2
. I suspect nightly Rust could do something similar today. (Nightly to be able to implement the Fn* traits.)
The biggest problem that has is figuring out the extent of the lambda:
- How does one decide if
foo().bar(_)
is|x| foo().bar(x)
ormatch foo() { t => |x| t.bar(x) }
? (Not unlike the postfix macro discussions.) - If one has
foo(_, _)
, is that|x, y| foo(x, y)
or|x| |y| foo(x, y)
, or something else? Can one do the other?
So I’m not sure how much value there is there over |x|
, which just isn’t that long.
(That said, currying can certainly be useful, so part of me likes the idea of being able to declare things as fn foo(x: i32)(y: i32) -> i32
so that foo(2): Fn(i32)->i32
. But then it’d always be foo(1)(2)
, never foo(1, 2)
.)