[Haskell-beginners] numerical integration over lists

Daniel Fischer daniel.is.fischer at googlemail.com
Sun Feb 5 19:09:22 CET 2012


On Sunday 05 February 2012, 18:18:54, Thomas Engel wrote:
> 
> > -- sums ys, where sums ks = zipWith (+) ks

Sigh, that's what you get for hopping to and fro while writing a mail.
That should have been

sums ks = zipWith (+) ks (tail ks)

like for differences

> > -- or areas xs ys = zipWith (*) (differenses xs) (means ys)
> > -- where means zs = map (/ 2) (sums zs)
> 
> I have changed the functions according your advice. But still I get an
> error:
> 
> differences :: Num a => [a] -> [a]
> differences xs = zipWith subtract xs (tail xs)
> 
> areas :: Floating a => [a] -> [a] -> [a]
> areas xs ys
>     = zipWith (*) (differences xs) (means ys)
>       where means zs = map (/ 2) (sums zs)
>                        where sums ks = zipWith (+) ks

It wasn't meant to be understood so, I intended differences etc. to be top-
level functions, that's more readable.




More information about the Beginners mailing list