Changes I made in the file:
1) Explained typing rules for functions with inout parameters.
3) Added link to the pseudocode
I saw the bug that you are trying to resolve and I think the first error is that the value parameter should be preceded with an underscore. The second error I think is in the syntax of the outer function's return type.
Why i think this way is because:
Consider example: In this code, every inner function has 2 params of Int type and is returning an Int type. Hence the outer function if of type (String)->(Int,Int)->Int
func operate(symbol: String) -> (Int, Int) -> Int {
// inner function to add two numbers
func add(num1:Int, num2:Int) -> Int {
return num1 + num2
}
// inner function to subtract two numbers
func subtract(num1:Int, num2:Int) -> Int {
return num1 - num2
}
let operation = (symbol == "+") ? add : subtract
return operation
}
let operation = operate(symbol: "+")
let result = operation(8, 3)
print("Result:", result)
But in this code:
If the inner function is returning 2 params then the outer function should be written like
func outerFunc( _ value: inout Float) -> (Float, Float) -> (Float, Float)
import _Differentiation
func outerFunc(value: inout Float) -> (Float, (Float) -> (Float, Float)) {
@differentiable(reverse, wrt: param)
func innerFunc(param: Float, other: Float) -> Float {
value += param
return value * param * 2.0
}
let valAndPullback = valueWithPullback(at: value, 2.0, of: innerFunc)
return (value + valAndPullback.value, valAndPullback.pullback)
}