Closed bwoebi closed 3 years ago
I would say when they're the same case and all the members also equate with ==
. Similarly, ===
should match when they're the same case and the members equate with ===
(like Option::Some(1) === Option::Some(1)
).
If we could do that sort of deeper definition of ===, I'm on board. Recall though that it may end up being recursive, since you can easily have an Enum var as a property of another Enum.
If, in the final design, the associated values are guaranteed to be constant expression values (including enums): Maybe the same functionality as WeakMap could be used to ensure that only one instance of Option::Some(1)
can exist at a given point of time with a given set of values, making ===
work by default. using the combination of enum name, case, and params could generate a unique key with serialize or a more compact equivalent (or even using serialize($value) as a key).
(or a WeakMap per enum class)
(A binary serialization format may be more efficient, but that's a separate issue)
If, in the final design, the associated values are guaranteed to be constant expression values (including enums)
That would make them a lot less useful. I think the way to go is to override the ===
behavior for enums specifically. But we'll deal with this once enums are accepted.
When are they equal? When their contents match weakly? strictly?