Hacker News new | ask | show | jobs
by bad_user 3432 days 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.

2 comments

> 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.

As suggested by the existence of this monstrosity, "theoretical computer scientists" have it right on this one.

https://dorey.github.io/JavaScript-Equality-Table/

>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.

That is not the intended use of Option/Maybe, the whole point of an `Option[A]` is to be different from `A`.
Not 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).
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.

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.

>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.