-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Description
I often make mistakes by using == between two objects that I shouldn't be comparing, such as comparing a number to an array of numbers or comparing a string to a character. The == comparison evaluates to false, but it wasn't the comparison I meant to make. For example,
a = [1,2,3]
b = 5
if a == b; # evaluates to falseI wish there were an equality-checking operator that would give an error for incompatible types, like in the example above. I'm not sure if the right implementation would be
- check if they have exactly the same type
- check some
<:subtyping relationship - check if they can
convertinto each other's types - check if they can
promoteinto a shared type
or something else, or multiple different operators for different purposes. There are plenty of equals-like operators in unicode (eg ≟, ≐). Regardless, the current situation where my mistakes result in silent falses causes me problems too often for comfort; I would much rather get an explicit error that I can correct.
What would be a good solution here?