Why "and" on an empty list returns true, does it imply that an empty list holds True? Sorry but I cannot read and comprehend this correctly, so please correct me. Thanks.
Prelude> and []
True
Prelude> or []
False
Why "and" on an empty list returns true, does it imply that an empty list holds True? Sorry but I cannot read and comprehend this correctly, so please correct me. Thanks.
Prelude> and []
True
Prelude> or []
False
One way to think about
True
andFalse
is as elements of the lattice ordered byFalse < True
.&&
and||
can be viewed as the binary "meet" (greatest lower bound) and "join" (least upper bound) operations for this lattice. Similarly,and
andor
are general finite meet and finite join operations. What isand []
? It's the greatest lower bound of[]
. ButTrue
is (vacuously) less than or equal to every element of[]
, so it's a lower bound of[]
, and (of course) it's greater than any other lower bound (the other beingFalse
), soand [] = True
. The algebraic view (thinking about monoids and such) turns out to be entirely equivalent to the order-theoretic view, but I think the order-theoretic one offers more visual intuition.