Instead of figuring out general protocol conformance for tuples, or at least figuring it out right now, why don’t we start off with the automatic protocols.
Right now, I think adding a tuple member to a nominal type breaks automatic
Equatable, etc. support, since it wouldn’t perform. I’ve read once that tuples are exploded before being passed to functions, but that behind-the-scenes doc was written in the function currying and they’re only tuple-to-tuple Swift 1 days. But the idea inspired me; what if we, instead of considering the tuple type as a whole when seeing if it’s wrapping nominal type could be
Equatable, we pierce the tuple and check each inner members’ conformance to
Equatable. This works recursively for nested tuples within the tuple.
This would apply to
Hashable too, and maybe the codable protocols. If we add sum tuples and/or fixed-size arrays, those would be pierced too. This does nothing for stand-alone compound types, but we could, once variadic generics are added, redo operators
!= by wrapping the tuples with a
struct inside the function definition and use the automatic support within it. This gets around the limitation that a naïve operator can only handle tuples with all
Equatable members but not one with nested tuples.
It doesn’t do anything for the general case, but may help the 80% case.