[Haskell-cafe] Why does not zipWith' exist

Kazu Yamamoto ( 山本和彦 ) kazu at iij.ad.jp
Fri Feb 1 08:32:32 CET 2013


Hello,

Many texts explain the following Fibonacci code:

fibs :: [Integer]
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)

But this code is very slow because evaluation of (+) is done
lazily. If we have the following strict zipWith', the code above
becomes much faster.

zipWith' f (a:as) (b:bs) = x `seq` x : zipWith' f as bs
  where
    x = f a b
zipWith' _ _ _ = []

Data.List defines foldl' against foldl. But it does not define
zipWith'. I'm curious why zipWith' does not exist in the standard
libraries.

--Kazu



More information about the Haskell-Cafe mailing list