mozilla/rust — pull request #6634 by bjz (2013-05-20 06:24:22+00:00)
Title: Add curry! macro

This adds a `curry!` macro that defines a named or anonymous curried function.

Example:

~~~rust
curry!(
fn mul(x: int, y: int) -> int {
x * y
}
)
let mul2 = mul(2);

assert_eq!(mul(2)(3), 6);
assert_eq!(mul2(3), 6);

let f: @fn(int) -> @fn(int) -> int = curry!(|x,y| x * y);
assert_eq!(f(2)(3), 6);
~~~

Notes:

- It would be nicer if the syntax for named declarations could be
`fn foo x: int -> y: int -> int` to reinforce the curried nature of the
resulting function, but this causes an ambiguity during macro expansion.
- Unfortunately generics are not supported due to the difficulty of
implementing type parameter lists in macros.
- Anonymous curried functions have difficulty inferring types.