[Haskell-cafe] Does this function already exist in the libraries?

Jason Dagit dagit at eecs.oregonstate.edu
Fri Sep 8 02:12:21 EDT 2006


Hello,

Sometimes I find that I have two lists I want to combine, but I only
want to combine them for as much as I have elements in both lists to
combine and then the rest I just want to pass through unmodified.

I've now found the following function useful in three different
programs I've written:

zipWith' :: (a -> a -> a) -> [a] -> [a] -> [a]
zipWith' _ [] ys = ys
zipWith' _ xs [] = xs
zipWith' f (x:xs) (y:ys) = f x y : zipWith' f xs ys

Does it already exist or maybe there is another natural solution to
use in its place?

Thanks,
Jason


More information about the Haskell-Cafe mailing list