Accumulator value for "and" and "or"

Hi or = foldl (||) False and = foldl (&&) True I can understand the rationale for the accumulator value - True && [] where [] = True and True || [] where [] = False Other than the practical convenience is there a reason for having the empty list in and and or equating to True and False? Thanks, Paul

On Fri, Sep 21, 2007 at 03:48:25AM +0100, PR Stanley wrote:
Hi or = foldl (||) False and = foldl (&&) True I can understand the rationale for the accumulator value - True && [] where [] = True and True || [] where [] = False Other than the practical convenience is there a reason for having the empty list in and and or equating to True and False? Thanks, Paul
It makes and and or into monoid morphisms. and (xs ++ ys) = and xs && and ys or (xs ++ ys) = or xs || or ys (PS are you sure you meant foldl? the standard definitons use foldr) Stefan

PR Stanley:
or = foldl (||) False and = foldl (&&) True [...] Other than the practical convenience is there a reason for having the empty list in and and or equating to True and False?
It might help to think of "and" as a kind of product, and "or" as a kind of sum, and note that: sum [] = 0 product [] = 1 If it seems odd that the product of an empty list should be 1, then consider why x^0 = 1 for any x /= 0, and so on.

PR Stanley wrote:
Hi or = foldl (||) False and = foldl (&&) True I can understand the rationale for the accumulator value - True && [] where [] = True and True || [] where [] = False Other than the practical convenience is there a reason for having the empty list in and and or equating to True and False? Thanks, Paul
Another way to think about this is to look at
any p = or . map p all p = and . map p
Now, "all even []" should hold, since everything in that list is even. But not "any even []" because there is no even number in the empty list. Twan
participants (4)
-
Matthew Brecknell
-
PR Stanley
-
Stefan O'Rear
-
Twan van Laarhoven