func main() -> () {
let tpl = (1, 3)
return print(
bimap(add(1))(add(2))(
tpl
)
)
}
// add (+) :: Num a => a -> a -> a
func add(_ a: Int) -> (Int) -> Int {
// new
return { b in a + b }
}
// bimap :: (a -> b) -> (c -> d) -> (a, c) -> (b, d)
func bimap<A, B, C, D>(_ f: @escaping (A) -> B) -> (@escaping (C) -> D) -> (A, C) -> (B, D) {
{
g in {
(a, c) in (f(a), g(c))
}
}
}
main()
The compiler says:
Missing arguments for parameters #1, #2 in call
My guess is that I can't pass an expression that evaluates to a tuple as a parameter.
Correct, you're calling bimap's result closure with a tuple of parameters. Swift doesn't automatically expand tuples when passed as function parameters, you need to break the tuple apart and pass each parameter separately.