[Haskell-cafe] Accumulator value for "and" and "or"

Stefan O'Rear stefanor at cox.net
Thu Sep 20 23:02:30 EDT 2007


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20070920/53ffa6be/attachment.bin


More information about the Haskell-Cafe mailing list