[Haskell-cafe] Why does not zipWith' exist

Daniel Fischer daniel.is.fischer at googlemail.com
Fri Feb 1 14:19:08 CET 2013


On Friday 01 February 2013, 13:43:59, Andres Löh wrote:
> 
> Right, I'm not arguing that it's impossible to produce a difference,
> but I think that if you're defining the sequence of fibs, the most
> likely scenario might be that you're actually interested in a prefix,

Right. If you only want one Fibonacci number with a not too small index, you 
should use a dedicated algorithm.

I was just providing a possible answer to

> Am I overlooking anything? What's your test?

to show how the desire for zipWith' might arise from the fibs example.

> and more importantly, you can still, from the outside, force the
> prefix even if you're only interested in a particular element. The
> second point, imho, is what makes zipWith inherently different from a
> function such as foldl'.

Right, and as I said in my first post, the fibs example is more of a scan than a 
zip. And for scans it's natural to consume the list in order [if you only want 
one element, a fold is the proper function].

> You can equivalently define zipWith' as a
> wrapper around zipWith:
> 
> zipWith' :: (a -> b -> c) -> [a] -> [b] -> [c]
> zipWith' f xs ys = strictify (zipWith f xs ys)
>   where
>     strictify :: [a] -> [a]
>     strictify []       = []
>     strictify (x : xs) = x `seq` x : strictify xs
> 
> You cannot easily do the same for foldl and foldl'.

I don't even see how one could do it non-easily.

Cheers,
Daniel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130201/be53b7f9/attachment.htm>


More information about the Haskell-Cafe mailing list