I'm new to Haskell and I'm trying to implement the sine approximation using MacLaurin's series using foldl on Haskell. I've already generated the list, and now I'm trying to get the summation using fold.
This is my code. I know I'm doing something wrong with the sin function, but I'm not sure what to do. I also have to pass x. If sin receives x as input, list will use the same value of x.
factorial n = product [1..n]
list x = [-1**n * ((x**(2*n+1))/factorial(2*n+1)) | n <- [0..29] ]
sin x = foldl (+) 0 list x
SOLVED: Correct solution:
factorial n = product [1..n]
list x = [(-1)**n * ((x**(2*n+1))/factorial(2*n+1)) | n <- [0..29] ]
sine x = foldl (+) 0 (list x)