# Currying in Rust

**URL:** <https://internals.rust-lang.org/t/currying-in-rust/10326>\
**Category:** language design\
**Created:** [June 1, 2019, 12:51am UTC](https://internals.rust-lang.org/t/currying-in-rust/10326 "2019-06-01T00:51:54Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![CAD97](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cad97/32/3460_2.png) [@CAD97](https://internals.rust-lang.org/u/CAD97)\
**Post date:** [June 1, 2019, 1:29am UTC](https://internals.rust-lang.org/t/currying-in-rust/10326/3 "2019-06-01T01:29:55Z")

</div>

Note that the inline curry almost works: `let add = |x| move |y| x + y;` is pefectly correct. Iff `x` is obviously used by move, then the `move` annotation for the inner closure isn’t required.

That said, a proposal to add first class currying syntax would have to explain how currying benefits Rust. I personally find a more explicit curried style, with `fn add(x, y)` and when I want to “curry it” I do `|y| add(my_x, y)`, to be unintrusive and very obvious as to what’s going on.

Return position `impl Trait` also makes the stable syntax honestly very close to the ideal, while exposing the costs quite clearly. Honestly, the only sugar I’d add is inlining the parameter names to the header to avoid separating them from their types like what a heavily curried function would look like on stable:

```rust
fn foo(a: A) -> impl FnOnce(B) -> impl FnOnce(C) -> impl FnOnce(D) -> impl FnOnce(E) -> F {
    |b| |c| |d| |e| {
        // "actual" fn body
        unimplemented!()
    }
}
```

---

_[View the full topic](https://internals.rust-lang.org/t/currying-in-rust/10326)._
