You are here

No Problem, Boole

Conditionals are part of most programming languages. Haskell has been, at times, accused of being a complex language. Conditionals in PHP defy expectations. Conditionals in Javascript are similarly non-logical. In both, '==' is non-transitive and '===' is non-reflexive. It might be expected that conditionals in Haskell are beyond human comprehension. These tables tell a different story.

All valid values of <expr> in the expression "if <expr> then True else False" and it's value.
False False
True True
undefined(Runtime Error)

NB: In the above table values that are semantically identical have been collapsed into a single row.

We can consider each row in the above table to be a Boolean value and construct the next table.

Equality comparisons among all Boolean values.
== False True undefined :: Bool
False True False (Runtime Error)
True False True (Runtime Error)
undefined (Runtime Error)(Runtime Error) (Runtime Error)

NB: The type annotation on undefined informs the type checker it is expected to be a Boolean value; undefined represents the "bottom" value, an instance of every type.

Learn (and use) Haskell. It has less complected elements than other languages. It is simpler and more expressive. Also, Boolean equality is transitive, commutative, and reflexive, as it should be.