# Tuples conform to Equatable, Comparable, and Hashable

**URL:** <https://forums.swift.org/t/tuples-conform-to-equatable-comparable-and-hashable/34156>\
**Category:** Pitches\
**Created:** [February 28, 2020, 2:58am UTC](https://forums.swift.org/t/tuples-conform-to-equatable-comparable-and-hashable/34156 "2020-02-28T02:58:44Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![Joe\_Groff](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joe_groff/32/1929_2.png) [@Joe\_Groff](https://forums.swift.org/u/Joe_Groff)\
**Post date:** [February 28, 2020, 9:48pm UTC](https://forums.swift.org/t/tuples-conform-to-equatable-comparable-and-hashable/34156/21 "2020-02-28T21:48:35Z")

</div>

> [@anandabits](#):
>
> This would also be the case in generic code like I posted above, correct? So it would just see `(Int, Int)` and the implicit conversion happens outside the generic code from the labeled to the unlabeled tuple types? If that's the case then I agree with your assessment that they're orthogonal issues.

That's right.

---

<div class="post-metadata">

**Author:** ![Alejandro](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/alejandro/32/46197_2.png) [@Alejandro](https://forums.swift.org/u/Alejandro)\
**Post date:** [February 29, 2020, 3:41am UTC](https://forums.swift.org/t/tuples-conform-to-equatable-comparable-and-hashable/34156/22 "2020-02-29T03:41:13Z")

</div>

> [@anandabits](#):
>
> ```swift
> func compareValues<T: Equatable>(_ lhs: T, _rhs: T) { ... }
> 
> // Is this allowed?
> compareValues((1, 2), (x: 1, 2: y))
> 
> // What about this?
> compareValues((y: 1, x: 2), (x: 1, 2: y))
> 
> // What about this?
> compareValues((a: 1, b: 2), (x: 1, 2: y))
> 
> ```

```swift
(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))
^

```

---

<div class="post-metadata">

**Author:** ![anandabits](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/anandabits/32/355_2.png) [@anandabits](https://forums.swift.org/u/anandabits)\
**Post date:** [February 29, 2020, 3:46am UTC](https://forums.swift.org/t/tuples-conform-to-equatable-comparable-and-hashable/34156/23 "2020-02-29T03:46:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Alejandro](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/alejandro/32/46197_2.png) [@Alejandro](https://forums.swift.org/u/Alejandro)\
**Post date:** [February 29, 2020, 3:47am UTC](https://forums.swift.org/t/tuples-conform-to-equatable-comparable-and-hashable/34156/24 "2020-02-29T03:47:52Z")

</div>

> [@GetSwifty](#):
>
> However, my opinion on this is completely dependent on the expected timeline for generalized Tuple protocol conformance. If we're talking sometime in the next year or two, I think it makes sense to wait. Otherwise if it's more of an "eventually it will probably be added", the use case for this pitch seems valuable enough to warrant being added soon.

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.

---

<div class="post-metadata">

**Author:** ![Alejandro](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/alejandro/32/46197_2.png) [@Alejandro](https://forums.swift.org/u/Alejandro)\
**Post date:** [February 29, 2020, 4:03am UTC](https://forums.swift.org/t/tuples-conform-to-equatable-comparable-and-hashable/34156/25 "2020-02-29T04:03:22Z")

</div>

> [@Karl](#):
>
> If we added `Collection` for homogenous tuples, and some kind of syntax shorthand to declare them, wouldn’t it essentially give us fixed-size arrays?
> 
> Is it worth going for that now, while we can, or waiting for something like generic value parameters? Bearing in mind that we already import fixed-size arrays from C as tuples, so any FSA design that isn’t a tuple will have large source breakage.

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._

---

<div class="post-metadata">

**Author:** ![Alejandro](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/alejandro/32/46197_2.png) [@Alejandro](https://forums.swift.org/u/Alejandro)\
**Post date:** [February 29, 2020, 4:07am UTC](https://forums.swift.org/t/tuples-conform-to-equatable-comparable-and-hashable/34156/26 "2020-02-29T04:07:32Z")

</div>

> [@DevAndArtist](#):
>
> Random question, shouldn‘t tuple also conform to `Error` when all types conform to `Error` as some kind of accumulator of errors which itself would be considered as an error?

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 😄

---

<div class="post-metadata">

**Author:** ![wowbagger](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/wowbagger/32/13847_2.png) [@wowbagger](https://forums.swift.org/u/wowbagger)\
**Post date:** [March 4, 2020, 5:59am UTC](https://forums.swift.org/t/tuples-conform-to-equatable-comparable-and-hashable/34156/27 "2020-03-04T05:59:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sveinhal](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/sveinhal/32/3992_2.png) [@sveinhal](https://forums.swift.org/u/sveinhal)\
**Post date:** [March 25, 2020, 9:42am UTC](https://forums.swift.org/t/tuples-conform-to-equatable-comparable-and-hashable/34156/28 "2020-03-25T09:42:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Alejandro](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/alejandro/32/46197_2.png) [@Alejandro](https://forums.swift.org/u/Alejandro)\
**Post date:** [March 25, 2020, 3:35pm UTC](https://forums.swift.org/t/tuples-conform-to-equatable-comparable-and-hashable/34156/29 "2020-03-25T15:35:47Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![anandabits](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/anandabits/32/355_2.png) [@anandabits](https://forums.swift.org/u/anandabits)\
**Post date:** [March 25, 2020, 3:37pm UTC](https://forums.swift.org/t/tuples-conform-to-equatable-comparable-and-hashable/34156/30 "2020-03-25T15:37:33Z")

</div>

> [@Alejandro](#):
>
> hopefully we're good to go!

🎉

---

<div class="post-metadata">

**Author:** ![sveinhal](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/sveinhal/32/3992_2.png) [@sveinhal](https://forums.swift.org/u/sveinhal)\
**Post date:** [April 24, 2020, 9:06am UTC](https://forums.swift.org/t/tuples-conform-to-equatable-comparable-and-hashable/34156/31 "2020-04-24T09:06:44Z")

</div>

Is it possible to push this forward into the review stage? What is missing for that to happen? Is it time and effort from @Alejandro, or is this awaiting on some external dependency? I don't know how one would go about in recruiting a review manager, etc, but I am super eager to get this moving forward, and would like to help in any limited capacity that I can. Maybe @Joe_Groff can assist with the formalities?

---

<div class="post-metadata">

**Author:** ![Alejandro](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/alejandro/32/46197_2.png) [@Alejandro](https://forums.swift.org/u/Alejandro)\
**Post date:** [April 24, 2020, 2:15pm UTC](https://forums.swift.org/t/tuples-conform-to-equatable-comparable-and-hashable/34156/32 "2020-04-24T14:15:49Z")

</div>

Joe had mentioned in the implementation that he had some work he needed to do (for another issue that they needed to back deploy), but it would allow the back deploy to have uniform behavior from the actual implementation. He just submitted a PR to allow me to update my back deploy implementation, so I'm waiting on that to to be merged. Besides that, my proposal has to wait like everybody else's. I'm trying as hard as I can to get this in!

---

<div class="post-metadata">

**Author:** ![sveinhal](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/sveinhal/32/3992_2.png) [@sveinhal](https://forums.swift.org/u/sveinhal)\
**Post date:** [April 24, 2020, 3:18pm UTC](https://forums.swift.org/t/tuples-conform-to-equatable-comparable-and-hashable/34156/33 "2020-04-24T15:18:07Z")

</div>

Thanks for the update. I didn’t mean to complain or push you, and I’m sorry if I came out rude.

I guess my question has as much to do with my (limited) understanding of this process, as with this specific proposal. I’m honestly curious about the status, as well as what the next formal step is. How a proposal goes from pitch to review is still not clear to me.

Also I’m super eager about this work! I guess that may come off as being pushy, but I’m honestly just really excited!

---

<div class="post-metadata">

**Author:** ![Alejandro](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/alejandro/32/46197_2.png) [@Alejandro](https://forums.swift.org/u/Alejandro)\
**Post date:** [April 24, 2020, 3:20pm UTC](https://forums.swift.org/t/tuples-conform-to-equatable-comparable-and-hashable/34156/34 "2020-04-24T15:20:08Z")

</div>

No no, you didn't come off rude at all don't worry!

---

<div class="post-metadata">

**Author:** ![sveinhal](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/sveinhal/32/3992_2.png) [@sveinhal](https://forums.swift.org/u/sveinhal)\
**Post date:** [April 24, 2020, 3:25pm UTC](https://forums.swift.org/t/tuples-conform-to-equatable-comparable-and-hashable/34156/35 "2020-04-24T15:25:33Z")

</div>

Again, thanks. But have you been assigned a review manager yet, or are you in some kind of queue to get one? Is there a formal requirement that the suggested implementation (which I understand must be given before the review, but not before a pitch) has to be approved from a technical point of view, ie. through a pull request review, before the proposal can be reviewed?

Sorry for asking perhaps stupid questions.

---

<div class="post-metadata">

**Author:** ![Alejandro](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/alejandro/32/46197_2.png) [@Alejandro](https://forums.swift.org/u/Alejandro)\
**Post date:** [April 24, 2020, 4:48pm UTC](https://forums.swift.org/t/tuples-conform-to-equatable-comparable-and-hashable/34156/36 "2020-04-24T16:48:53Z")

</div>

I’m in the same boat as you, I don’t have much information to provide on the process. This will most likely wait until the 5.4 process because 5.3 has already had its cutoff date.

---

<div class="post-metadata">

**Author:** ![Michael\_Brown](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/michael_brown/32/2480_2.png) [@Michael\_Brown](https://forums.swift.org/u/Michael_Brown)\
**Post date:** [September 22, 2020, 10:14am UTC](https://forums.swift.org/t/tuples-conform-to-equatable-comparable-and-hashable/34156/37 "2020-09-22T10:14:56Z")

</div>

Just wanted to check: this includes conformances for `Void`, right? It's not mentioned explicitly, and in the proposal it says:

> all tuples whose elements are themselves `Equatable` , `Comparable` , and `Hashable` .

Which, depending on your interpretation, would exclude `Void`, since it has no elements.

Can someone confirm that this proposal does in fact include `Void`?

---

<div class="post-metadata">

**Author:** ![Michael\_Brown](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/michael_brown/32/2480_2.png) [@Michael\_Brown](https://forums.swift.org/u/Michael_Brown)\
**Post date:** [September 22, 2020, 10:22am UTC](https://forums.swift.org/t/tuples-conform-to-equatable-comparable-and-hashable/34156/38 "2020-09-22T10:22:07Z")

</div>

I guess the branch name of the [PR for the implementation](https://github.com/apple/swift/pull/28833) answers my question: `Azoy:void-is-equatable` 😄

---

<div class="post-metadata">

**Author:** ![Joe\_Groff](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joe_groff/32/1929_2.png) [@Joe\_Groff](https://forums.swift.org/u/Joe_Groff)\
**Post date:** [September 22, 2020, 2:54pm UTC](https://forums.swift.org/t/tuples-conform-to-equatable-comparable-and-hashable/34156/39 "2020-09-22T14:54:53Z")

</div>

You're right. "All elements are X" is true when there are no elements, since X is never false in that case.

---

<div class="post-metadata">

**Author:** ![Lantua](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lantua/32/8868_2.png) [@Lantua](https://forums.swift.org/u/Lantua)\
**Post date:** [September 22, 2020, 2:58pm UTC](https://forums.swift.org/t/tuples-conform-to-equatable-comparable-and-hashable/34156/40 "2020-09-22T14:58:25Z")

</div>

> [@Joe\_Groff](#):
>
> You're right. "All elements are X" is true when there are no elements, since X is never false in that case.

What a [vacuous](https://en.wikipedia.org/wiki/Vacuous_truth) statement. (Sorry, I'll see myself out).

[Previous page](https://forums.swift.org/t/tuples-conform-to-equatable-comparable-and-hashable/34156.md?page=1)

[Next page](https://forums.swift.org/t/tuples-conform-to-equatable-comparable-and-hashable/34156.md?page=3)
