[Haskell-cafe] Why does not zipWith' exist

2013-01-31 Thread 山本和彦
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 `

Re: [Haskell-cafe] Why does not zipWith' exist

2013-02-01 Thread Andres Löh
Hi Kazu. I'd be surprised if zipWith' yields significant improvements. In the case of foldl', the strictness affects an internal value (the accumulator). However, in the case of zipWith', you're just forcing the result a bit more, but I guess the "normal" use pattern of fibs is that you want to se

Re: [Haskell-cafe] Why does not zipWith' exist

2013-02-01 Thread Daniel Fischer
On Friday 01 February 2013, 12:50:18, Andres Löh wrote: > Hi Kazu. > > I'd be surprised if zipWith' yields significant improvements. In the > case of foldl', the strictness affects an internal value (the > accumulator). However, in the case of zipWith', you're just forcing > the result a bit more,

Re: [Haskell-cafe] Why does not zipWith' exist

2013-02-01 Thread Daniel Fischer
On Friday 01 February 2013, 13:06:09, Daniel Fischer wrote: > > zipWith' would [I haven't tested, but I'm rather confident] make a > difference if you benchmarked > > bench "name" (whnf (fibs !!) 10) > > etc. Well, it took a little bit of persuasion to let GHC not cache the list(s), but

Re: [Haskell-cafe] Why does not zipWith' exist

2013-02-01 Thread Andres Löh
> Well, it took a little bit of persuasion to let GHC not cache the list(s), but > with > > > fibs :: Int -> Integer > fibs k = igo i !! k > where > i | k < 100 = 1 > | otherwise = 2 > igo :: Integer -> [Integer] > igo i = let go = 0 : i : zipWith (+) go (tail go) in go >

Re: [Haskell-cafe] Why does not zipWith' exist

2013-02-01 Thread Daniel Fischer
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

Re: [Haskell-cafe] Why does not zipWith' exist

2013-02-01 Thread Niklas Hambüchen
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 tha

Re: [Haskell-cafe] Why does not zipWith' exist

2013-02-01 Thread 山本和彦
Hi, > zipWith' would [I haven't tested, but I'm rather confident] make a difference > if > you benchmarked > > bench "name" (whnf (fibs !!) 10) > > etc. Yes. fibs is slow if used with "!!". --Kazu ___ Haskell-Cafe mailing list Haskell-Cafe

Re: [Haskell-cafe] Why does not zipWith' exist

2013-02-01 Thread 山本和彦
> 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, > and more importantly, you can still, from the outside, force the > prefix even if you