
25 Jun
2005
25 Jun
'05
5:49 p.m.
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