Why “and []” is True and “or []” is False

2020-02-01 04:16发布

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

7条回答
等我变得足够好
2楼-- · 2020-02-01 05:07

One way to think about True and False is as elements of the lattice ordered by False < True. && and || can be viewed as the binary "meet" (greatest lower bound) and "join" (least upper bound) operations for this lattice. Similarly, and and or are general finite meet and finite join operations. What is and []? It's the greatest lower bound of []. But True 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 being False), so and [] = 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.

查看更多
登录 后发表回答