# \[Pitch #2\] Add \`isIdentical\` Methods for Quick Comparisons to Concrete Types

**URL:** <https://forums.swift.org/t/pitch-2-add-isidentical-methods-for-quick-comparisons-to-concrete-types/80496>\
**Category:** Pitches\
**Created:** [June 16, 2025, 6:00pm UTC](https://forums.swift.org/t/pitch-2-add-isidentical-methods-for-quick-comparisons-to-concrete-types/80496 "2025-06-16T18:00:16Z")\
**Posts on this page:** 1\
**Showing post:** 92

<div class="post-metadata">

**Author:** ![vanvoorden](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/vanvoorden/32/33619_2.png) [@vanvoorden](https://forums.swift.org/u/vanvoorden)\
**Post date:** [August 19, 2025, 11:44pm UTC](https://forums.swift.org/t/pitch-2-add-isidentical-methods-for-quick-comparisons-to-concrete-types/80496/92 "2025-08-19T23:44:22Z")

</div>

> [@grynspan](#):
>
> I'm in favour of defining `===` and `!==` for this purpose, as they effectively mean "is identical" for object references today, but I can appreciate that not everyone wants more operators in the language. 🙂

> **Discussion about Infix Operators and Symmetry**
>
> Just an observation here specifically WRT the discussion about enforcing semantics across all concrete types:
> 
> > [@\[Pitch #2\] Add \`isKnownIdentical\` Method for Quick Comparisons to \`Equatable\`](https://forums.swift.org/t/pitch-2-add-isknownidentical-method-for-quick-comparisons-to-equatable/80497/20):
> >
> > > [@\[Pitch #2\] Add \`isKnownIdentical\` Method for Quick Comparisons to \`Equatable\`](https://forums.swift.org/t/pitch-2-add-isknownidentical-method-for-quick-comparisons-to-equatable/80497/17):
> > >
> > > The main objection I have to `lhs.isKnownIdentical(to: rhs)` is that identity checking, like equality checking, should not treat the two sides differently. `a.isKnownIdentical(to: b)` should be the same as `b.isKnownIdentical(to: a)`. And it is. But `a?.isKnownIdentical(to: b)` is not the same as `b?.isKnownIdentical(to: a)` and that is easy to miss.
> > 
> > On this note, it's also worth pointing out that the section on [Argument Labels](https://www.swift.org/documentation/api-design-guidelines/#argument-labels) in the _Swift API Design Guidelines_ calls out the situation you're talking about, saying
> > 
> > > - **Omit all labels when arguments can’t be usefully distinguished** , e.g. `min(number1, number2)`, `zip(sequence1, sequence2)`.
> > 
> > While that does seem to focus specifically on the labels, I think there's an unstated implication that an API that doesn't distinguish between two (or more) arguments shouldn't privilege one of them by making it the receiver—and the prior art of functions like `min` and `zip` reinforce that.
> 
> So the "unstated implication" here is that _if_ we defined this operation through `===` we are limiting the flexibility that library maintainers might need.
> 
> Suppose for example a library maintainer had some code path where they needed to forward `===` through to `Span.isIdentical`:
> 
> ```swift
> struct S {
> static func ===(_ lhs: Self, _ rhs: Self) -> Bool {
> guard
> lhs.hasStorage,
> rhs.hasStorage
> else {
> return lhs.span.isIdentical(to: rhs.span)
> }
> return lhs.storage === rhs.storage
> }
> }
> 
> ```
> 
> So it's not completely idiomatic here for `S` to "promote" `lhs` to be the receiver of the `isIdentical` operation on `span`. Unless maybe if `Span.isIdentical` gave us the formal guarantee of symmetry… which I do not currently see guaranteed in the documentation.
> 
> The option then might be to enforce that `===` must _also_ be an symmetrical operation such that `a === b` is the same as `b === a`. But I'm not yet persuaded that symmetry _must_ be enforced at an abstract level across _all_ these operations. I have no problem with library maintainers of a _concrete_ type making that decision for themselves when appropriate to do so. I'm just not convinced we need to always enforce that everywhere.
> 
> …
> 
> But now that I go back and think through again… there must be _some_ kind of convention here that infix operators do not take labels and still distinguish between arguments. How else could a `<` implementation not just flip the arguments and return the wrong answer?

It looks like the declaration of `===` does _not_ formally confirm Reflexivity, Symmetry, _or_ Transitivity:

> <https://github.com/swiftlang/swift/blob/swift-6.1.2-RELEASE/stdlib/public/core/Equatable.swift#L213-L258>

So unless maybe that is hiding out somewhere else… we do not explicitly guarantee that `x === y` must imply `y === x`. Which is surprising…

I do think that even without this explicit semantic guarantee any product engineer that looks at `===` probably _expects_ it to respect Symmetry. And if we defined a new set of `===` operators on these types I think it would be fair to assume those project engineers also expect Symmetry there.

---

_[View the full topic](https://forums.swift.org/t/pitch-2-add-isidentical-methods-for-quick-comparisons-to-concrete-types/80496)._
