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
To expand on the answer by Dan, the conjunction of an empty list of truth values being true True
allows you to extend the expected properties of conjunction to that case.
For instance, we would expect that,
and (xs ++ ys) = (and xs) && (and ys)
and for all xs
we have, xs = xs ++ []
so,
and xs
= and (xs ++ [])
= (and xs) && (and [])
considering that and xs
might be True
or False
it follows that,
True = True && (and [])
False = False && (and [])
Therefore we must have that and []
is True
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With