Tuples composed of Equatable types should automatically be equatable
| Originator: | GriotSpeak | ||
| Number: | rdar://17823187 | Date Originated: | 2014-07-27 |
| Status: | Open | Resolved: | |
| Product: | Swift | Product Version: | |
| Classification: | Enhancement | Reproducible: |
Summary:
If I try to compare a double of Ints, the compiler gives an error.
Steps to Reproduce:
// this method makes it compile
//private func ==(first:(quotient:Int, modulus:Int), second:(quotient:Int, modulus:Int)) -> Bool {
// return (first.0 == second.0) && (first.1 == second.1)
//}
internal extension Int {
func divMod(other:Int) -> (quotient:Int, modulus:Int) {
let remainder = self % other
let quotient = self / (other - remainder)
return (quotient, remainder)
}
public func testDivMod() -> Bool {
var success = true
success = success || (13.divMod(4) == (quotient:3, modulus:1))
return success
}
}
Expected Results:
I shouldn't need the implementation for ==(a:(Int, Int), b:(Int, Int))->Bool
Actual Results:
I do need the implementation for ==(a:(Int, Int), b:(Int, Int))->Bool
Version:
Version 6.0 (6A267n)
Notes: I think that Comparability could also be inferred.
Configuration:
Attachments:
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
Possible implementation
You can implement this yourself, and you may want to add the following to the radar as a proposed implementation. It's tedious and cannot be made generic up to an arbitrary length tuple (which is the same problem Scala has. Scala can handle up to a 22-element tuple because that's how many times they copied the code: http://www.scala-lang.org/api/2.11.2/#scala.Product22). But still, it can be made useful for any real-world tuples.
https://gist.github.com/rnapier/411a710ebb725677b25d