Tuples conform to Equatable, Comparable, and Hashable

That's right.

(swift) func equals<T: Equatable>(_ lhs: T, _ rhs: T) -> Bool {
          lhs == rhs
        }
(swift) equals((1, 2), (x: 1, y: 2))
// r0 : Bool = true
(swift) equals((y: 1, x: 2), (x: 1, y: 2))
<REPL Input>:1:1: error: type of expression is ambiguous without more context
equals((y: 1, x: 2), (x: 1, y: 2))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(swift) equals((a: 1, b: 2), (x: 1, y: 2))
<REPL Input>:1:1: error: conflicting arguments to generic parameter 'T' ('(a: Int, b: Int)' vs. '(x: Int, y: Int)')
equals((a: 1, b: 2), (x: 1, y: 2))
^
2 Likes

Perfect, thanks for checking it with your build! I'm really excited to see this moving ahead!

I'm not quite sure what the timeline is, but the three features that are needed for general purpose tuple conformances to be useful are:

  1. Parameterized Extensions
  2. Variadic Generics
  3. Extend Structural Types

Some of these are certainly much more difficult to implement than others, but all of them must go through designing phase, evolution, etc. Next year or two feels like a good estimate for these, but even if we'll be able to reimplement these conformances by then I still feel that this proposal is useful for users who would like to use this now. From a user standpoint they don't have to worry about migration or anything like that when those become available after they've already started using these conformances in this proposal.

2 Likes

Yes, that would essentially provide us with fixed-size arrays. My personal opinion is to hold off on other convenience conformances until general purpose conformances for tuples arrive. In any case, many may disagree and may start their own thread to propose them.

Spoiler alert: adding new builtin conformances after my initial patch is incredibly easy, but you didn't hear that from me.

1 Like

This could make sense, but I'm not too versed in any sort of error handling in Swift. Feel free to start a new thread discussing this if you think there's something worth hashing over about :smile:

I think it would be very beneficial that tuples conform to Hashable, because then tuples can be used for ID types in Identifiable conformances.

4 Likes

What's the status on this? I'm super eager for this moving forward to a proper review stage?

I had some late feedback on the implementation that I had to address, but I just pushed those changes so hopefully we're good to go!

5 Likes

:tada:

1 Like
Terms of Service

Privacy Policy

Cookie Policy