When you write a generic function in Swift, you are making a universal declaration. That is, "for all types T and U that conform to Custom, you can call this function schedule passing in a T and a U".
The Swift type system will ensure this is the case. Suppose you also added a conformance String: Custom but then didn't provide an implementation of compute for strings. There would be no compute function to call within the body of schedule. The compiler won't let this happen.
The compiler does this only through the method signatures; it does not look at the implementation of a generic function to check everything is OK. Instead, it requires that the only capabilities used in a generic function's body on generic types must come from the constraints you put on the generic types – in this case, other functions or properties made available by your Custom constraint.
The easiest way to resolve this is to make compute a requirement of the protocol. That way, the only way you can make Float conform to Custom is if you provide that function. And that means functions that constrain to Custom are guaranteed to be able to call it:
protocol Custom {
static func compute(_ x: Self, _ y: Self) -> Self
}
Now, if you try and write extension Float: Custom { } you'll get a compiler error telling you Float doesn't conform, because you haven't implemented custom. If you do, it'll compile, and you could use it to implement schedule:
extension Float: Custom {
static func compute(_ x: Float, _ y: Float) -> Float {
return x+y
}
}
func schedule<T: Custom>(x: T, y: T) {
T.compute(x, y)
}
Unfortunately, this still doesn't do what you want because this assumes x and y are of the same type. You want multiple dispatch – to drive different logic from two different types. Implementing this can be a pain, because you need to cater for every possible combination, and how to best do it really depends on what you're trying to achieve. I'd suggest googling "multiple dispatch" for ideas. Though there's not much material about Swift, so you'll have to adapt patterns from C++ or Java articles, so you may want to familiarize yourself with Swift generics first with simpler single-dispatch cases.