[Haskell-cafe] Why does not zipWith' exist
Niklas Hambüchen
mail at nh2.me
Fri Feb 1 16:52:59 CET 2013
I recently asked a similar question about strict scans (e.g. scanl')
and got the same response to use a strictify function.
Although I would argue that fun' is syntactically more convenient than
(strictList . fun), I'd agree that composition is good.
Maybe it would make sense to add to have that strictList function in
Data.List instead?
On Fri 01 Feb 2013 13:19:08 GMT, Daniel Fischer wrote:
> 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
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
More information about the Haskell-Cafe
mailing list