New Issue: Should Chapel support '==='/'!==' operators for checking identity equivalence?

16853, “bradcray”, “Should Chapel support ‘===’/’!==’ operators for checking identity equivalence?”, “2020-12-11T01:47:31Z”

Swift and Python support distinct ==/!= and ===/!== operators to distinguish between comparing the logical values of classes and their identities.

In Chapel, we have considered disabling ==/!= overloads on classes (see https://github.com/chapel-lang/chapel/issues/13048) in order to avoid breaking the fundamental ability to determine whether one class variable points to the same object as another or contains nil. This issue proposes an alternative, which would be to support both flavors of operators for classes in Chapel where the implementations of ==/!= default to ===/!== for each class if the user hasn’t supplied their own overload of ==/!=. ===/!== would not be permitted to be overloaded.

Advantages:

  • would give users coming from Python the ability to defined ==/!= on their classes as they are accustomed to
  • would make classes more symmetrical in terms of permitting both ordered (e.g., <) and unordered (e.g., ==) comparisons
  • is backwards compatible for user code

Disadvantages:

  • it’s a change to the language
  • internal/standard/package modules would need to be audited to find cases that are expecting ==/!= on classes to be about identity to use ===/!== instead
  • could cause confusion to users coming from other languages (like Javascript?) where === is supported for values as well (and means “applying no coercions,” as I understand it?)