Why does `and` return True for empty foldable but `or` return False in Haskell? [duplicate]

  • A+

This question already has an answer here:

Is there a reason that would explain whether such results are to be expected? Are they better than being undefined?

>>> any (const True) [] False  >>> any (const False) [] False  >>> or [] False  >>> and [] True 

I don't really understand what the Report is trying to say:

-- and returns the conjunction of a Boolean list. For the result to be -- True, the list must be finite; False, however, results from a False -- value at a finite index of a finite or infinite list. or is the -- disjunctive dual of and.  and, or     :: [Bool]    -> Bool and         =  foldr    (&&)    True or          =  foldr    (||)    False 


This is true of most languages with comparable functions. It is because "True" is the identity of "&&" (meaning x && True == x). Likewise, "False" is the identity of "||" (meaning x || False == x).


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: