On Jun 22, 2007, at 2:30 PM, Dan Weston wrote:
This is how I think of it: lazyIntMult :: Int -> Int -> Int lazyIntMult 0 _ = 0 lazyIntMult _ 0 = 0 lazyIntMult a b = a * b *Q> 0 * (5 `div` 0) *** Exception: divide by zero *Q> 0 `lazyIntMult` (5 `div` 0) 0 foldr evaluates a `f` (b `f` (c `f` ...))Only f knows which arguments are strict and in which order to evaluate them. foldr knows nothing about evaluation order.
And, indeed, if you foldr a function with left zeroes, and you check for them explicitly as lazyIntMult and (||) do, then foldr is guaranteed to terminate early if it finds a zero.
z is a left zero of op if for all x, z `op` x = z.This isn't the only time foldr will terminate early, but it is an important one.
-Jan-Willem Maessen
Dan
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe