4 ms·
> `5 == Just 5` fails. But in Swift this works like you would want Why in the world would you want those two to be equal when they obviously don't represent th
by bad_user 10y ago
> `5 == Just 5` fails. But in Swift this works like you would want
Why in the world would you want those two to be equal when they obviously don't represent the same thing?
That doesn't make sense, not even if they have the exact same memory representation, in which case I'm pretty sure it has been a compromise, which would mean you're still dealing with `null` with some lipstick on it, making that type behave inconsistently with other types in the language.
This kind of misguided convenience is exactly why equality tests in most languages are in general a clusterfuck.
- majewsky 10y ago> Why in the world would you want those two to be equal when they obviously don't represent the same thing? This is the difference between normal people and theoretical computer scientists, summarized in one sentence.
- wyager 10y agoAs suggested by the existence of this monstrosity, "theoretical computer scientists" have it right on this one. https://dorey.github.io/JavaScript-Equality-Table/ https://dorey.github.io/JavaScript-Equality-Table/
- coldtea 10y ago>Why in the world would you want those two to be equal when they obviously don't represent the same thing? Because I care for intended use, not ontology.
- bad_user 10y agoThat is not the intended use of Option/Maybe, the whole point of an `Option[A]` is to be different from `A`.
- coldtea 10y agoNot the intended use of Option[A] -- the intended use of A. Option is just a safeguard, and for the check with A that capability is not needed at all (if it's Just A it can ...just equal to A).
- bad_user 10y agoOption isn't a safeguard, it expresses missing values in a way that doesn't violate the Liskov Substitution Principle, otherwise you might as well work with `null` along with some syntactic sugar. And they are different because the types say so. By allowing them to be equal, you're implicitly converting one into the other. That's weak typing by definition, a hole in the type system that can be abused. So why have types at all? Dynamic typing is much more convenient and Clojure deals with nulls by conventions just fine.
- coldtea 10y ago>Option isn't a safeguard, it expresses missing values in a way that doesn't violate the Liskov Substitution Principle, otherwise you might as well work with `null` along with some syntactic sugar. Again, it's the use that makes it a safe guard, not its ontology. >And they are different because the types say so. By allowing them to be equal, you're implicitly converting one into the other. Which is fine sometimes, when you explicitly need to do it a lot. >That's weak typing by definition, a hole in the type system that can be abused. Any examples of how A = Just A can be abused in any meaningful way? >So why have types at all? Because I don't believe in the Slippery Slope fallacy, and some types are better than no types at all, but exceptions can be OK too.