Well, the case of the built-in numeric types is somewhat different,
but most functions automatically short circuit, since Haskell uses
lazy evaluation.

For instance, it's perfectly okay to define
myAnd = foldr (&&) True
Note that this terminates on infinite lists which contain False as a value:
myAnd (False : repeat True)
will evaluate to False pretty much immediately.

 - Cale

On 25/06/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> 
>    Some simplifications might help you here...
> 
>    > prodList [] = 1
>    > prodList (0:xs) = 0
>    > prodList (x:xs) = x * prodList xs
> 
>    Simplified:
>    prodList xs = foldl (*) 1 xs
> 
> But my original at least made some provision for short circuiting the
> whole operation if the list contained a 0.  As far as I can figure,
> fold, map, etc., are not suitable for any situation in which
> short-circuiting would be desirable (e.g. and, or, etc.).  Am I wrong?
> 
> (I realize that, given that the function product is already available,
> there is no point in defining my function prodList above, but my
> question is a more general one, having to do with how best to
> implement short-circuiting.)
> 
> Thanks!
> 
> kj
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to