I tried to implement the Taylor sequence for the exponential function and I get a huge load of errors, which I don't fully understand, as all the code segments in themselves work... Could someone explain the error and a workaround please:
top x = map (x^) [0..]
bottom = foldr (*) 1 [1..]
whole x = zipWith (/) (top x) bottom
Thanks in advance!
Okay, I figured it out. The problem was that bottom
wasn't actually a list of all possible factorials.
To solve the problem, I had to use scanl
instead of foldr
:
bottom = scanl (*) 1 [1..]