Tuples conform to Equatable

Is there really an obvious (and mandatory, non-customizable) Comparable-conformance that would make sense for eg these:

let person = (firstName: "Ada", lastName: "Lovelace", birthDate: Date(/*...*/))
let coordinate = (latitude: 40.689263, longitude: -74.044505)
let dmy = (day: 30, month: 1, year: 2020)
let ymd = (year: 2020, month: 1, day: 30)  

?

If so, I assume that the same Comparable conformance will be automatically synthesized for struct, ie that the following will compile in a future version of Swift:

struct ImperialMeasure : Hashable, Comparable { // Error (currently, because of Comparable)
    var inches: Double
    var feet: Double
    var yards: Double
    var miles: Double
}

I couldn't come up with a less contrived (and stupidly designed) type, but you get the idea: The order of the stored properties would make or break measureA < measureB semantically (something which is not the case for measureA == measureB and hashing).

What I'm trying to say is that while needing to write custom Equatable (and Hashable) conformances is not uncommon (there are cases where the automatically synthesized conformances won't make sense), it would probably be much more common for Comparable, perhaps even so common that it would be better to leave it as it is (ie no automatically synthesized Comparable conformances). And if so, that would probably mean that there is no obvious Comparable conformance that makes enough sense for all tuples to be worth its weight (in potential confusion etc) either.

Sorry if all of this has already been discussed or clarified elsewhere.

1 Like