[Haskell-cafe] cumulative sum
chad.scherrer at gmail.com
Mon Oct 2 12:27:49 EDT 2006
scanl (+) 0
for the cumulative sum
>From there the zipWith idea you mentioned seems like the way to go.
> I have two lists, p and lambda (both are finite). I would like to
> 1) the cumulative sum of lambda, ie if
> lambda = [lambda1,lambda2,lambda3,...]
> csum lambda = [lambda1,lambda1+lambda2,lambda1+lambda2+lambda3,...]
> 2) the cumulative sum of p*lambda (multiplication elementwise)
> Once I know how to do the first, I know how to do the second I guess
> (doing the multiplication using zipWith to get the p*lambda list, but
> I would be interested in any other suggestions). Currently I take and
> sum, but then I am calculating the same sums many times.
More information about the Haskell-Cafe