Missing arguments for parameters #1, #2 in call

I have the following code:

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.

So, I have two questions:

  • Is my hypothesis right ?
  • What does the error message mean ?

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.

print(
    bimap(add(1))(add(2))(
        tpl.0, tpl.1
    )
)
1 Like

Thank you very much. Do you know whether this is an intended design or this is a bug ?

This was actually intentionally removed in Swift 3:

1 Like