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

Udo Stenzel u.stenzel at web.de
Sun Jun 26 13:12:19 EDT 2005


Scott Turner wrote:
 
> It's still possible to use fold and get short circuiting with good memory 
> usage.
>   upTo pred = foldr (\a -> \xs -> if pred a then [a] else a:xs) []
>   prodList = foldl' (*) 1 . upTo (== 0)
> It might be considered cheating, but AFAICT the test for ==0 needs to be 
> separated from the multiplication proper.

They don't need to be separated, though the result is no longer as clear
as one might wish:

prodList xs = foldr (\x f a -> if x == 0 then 0 else f $! x * a) id xs 1


Udo.
-- 
Wise men talk because they have something to say; fools, because they
have to say something.  --  Plato (429-347 BC)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org//pipermail/haskell-cafe/attachments/20050626/6af6e0cd/attachment.bin


More information about the Haskell-Cafe mailing list