[Haskell-cafe] Noob error: Type b -> c b Does not match IO a

kynn at panix.com kynn at panix.com
Sat Jun 25 17:49:39 EDT 2005


   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



More information about the Haskell-Cafe mailing list