You can't today.

Your identity function is a "true" identity function, but it only takes a function of one parameter and one result. The type checker has an explicit rule that a function of multiple arguments can be converted to a function of one argument taking a tuple argument. So when you pass in a function taking multiple arguments, such as +, its converted into a function taking one argument at the call site.

This also explains why type(of:) produces a different result for add vs identity(add). When you pass add as an argument to identity, the conversion takes place since the argument type is (T) -> U. So the return value of identity() has a different type than add itself, because the conversion changes its type to ((Int, Int)) -> Int.

5 Likes