fold{l|r} and short-circuit evaluation

Tom Pledger Tom.Pledger at peace.com
Wed Oct 15 15:38:28 EDT 2003


Scott Turner writes:
 :
 | Alternatively, since nextSame1 is called only in the context where
 | the expected value is known, you could give it the expected value
 | as another parameter.  Then it would be possible to sometimes avoid
 | referencing the right operand at all. It would be called
 |      foldr (nextSame1 a) (Just a) as

Once you do that, you can simplify the result type of the fold, from
'Maybe a' to Bool.

    allSame []     = True
    allSame (a:as) = all (a==) as



More information about the Haskell-Cafe mailing list