NOTE. This question was asked, and Swift 2.1 was the last.
Given:
class IntWrapper {
var i: Int = 1
}
func add(inout m: Int, i: Int) {
m += i
}
And a higher order function
func apply() -> (inout i: Int) -> () -> () {
return { (inout i: Int) -> () -> () in
return {
add(&i, i: 1)
}
}
}
An application as such results in a change in the value of a member variable:
var intW = IntWrapper()
print(intW.i)
apply()(i: &intW.i)()
print(intW.i)
However, when the function changes to curry form
func apply()(inout i: Int)() -> () {
add(&i, i: 1)
}
It is used when changing the value of a member variable:
var intW = IntWrapper()
print(intW.i)
apply()(i: &intW.i)()
print(intW.i)
I am curious why this is so. I always thought that cardiac syntax was sugar for a higher ordered form of function, but there seems to be semantic differences.
, swift, , , , , , , . ?

