在Swift中讨论,将来会有新的声明语法吗?

Mic*_*ahl 4 swift

刚刚在Linux上安装了Swift来检查它.

尝试一个小例子的currying会导致警告curry的语法将来会发生变化,但是我找不到任何关于这个新语法的样子.

我试过的例子:

func do_stuff(x: Int) (y: Int) (z: Int) -> Int {
    return (x - y) * z
}
let curry_fun = do_stuff(42)
let x = curry_fun(y: 7)(z: 3)
Run Code Online (Sandbox Code Playgroud)

编译此示例会导致以下警告:

warning: curried function declaration syntax will be removed in a future version of Swift; use a single parameter list
func do_stuff(x: Int) (y: Int) (z: Int) -> Int {
             ^~~~~~~~~~~~~~~~~~~~~~~~~~
                    ,        ,
Run Code Online (Sandbox Code Playgroud)

那么在未来的swift中,currying会是什么样子呢?

我确实尝试了类似的东西 func do_stuff(x: Int, y: Int, z: Int) -> Int... ,但是我找不到用这个函数来干嘛的方法.

小智 21

只删除声明语法,例如 func(a: Int)(b:Int) -> Int

func curry(a: Int)(b: Int) -> Int {
    return a + b
}
Run Code Online (Sandbox Code Playgroud)

相当于:

func newCurry(a: Int) -> (b: Int) -> Int {
    return { b in
        return a + b
    }
}
Run Code Online (Sandbox Code Playgroud)