apple == orange
If you are reading this, you are probably a programmer. Let me ask you, for just a moment, to step out of your programmer shoes and answer these questions:
- Is this apple equal to that orange?
- Is that cloud equal to this house?
- Is my backpack equal to my television?
The obvious answer is "no" to all of these. And so (please step back into your programmer shoes) we see in many languages I can ask a similar question:
In Java:
apple.equals(orange)
Or in Clojure:
(= apple orange)
The answer to both questions is unsurprisingly false
.
And in Haskell?
apple == orange
Type error! The compiler is saying I cannot even ask the question.
What model of reality is Haskell asserting?
Is it telling me that I need to convert the apple and orange into values of the same type?
Fruit {name = "apple"} == Fruit {name = "orange"}
Is this question really different from apple == orange
?
Which model (Haskell's or Clojure's) more closely models reality?
Is this behavior intentionally designed into Haskell or is it incidental behavior due to the choice of type system?
Does this behavior make Haskell better or worse than a hypothetical Haskell that allowed the question to be asked?
Deep questions.