Q:

Haskell: Lists and foldl

I have a series of numbers: 0, 1, 3, 6, 10, 15,...
Basically, you add 1, then you add 2, then add 3, etc.
I have to make a function where I return this series of numbers in a list up to a given number, n. I want to use foldl.
so, series 5 should return [0, 1, 3, 6, 10, 15]
Here is what I have so far:
eachElem n = foldl (+) 0 [0..n]

series n = [x | x <- [(eachElem 0), (eachElem 1)..(eachElem n)]]

Basically, I figured that each element in the list was a foldl operation, and so I made a separate helper function (eachElem) to accomplish this.
However, it is returning a list much larger than what I want. 
Eg. series 3 => [0,1,2,3,4,5,6] when it should really return [0,1,3,6]
Any ideas why this is? 

A:

scanl is better suited to what you're doing.
Its type is scanl :: (a -> b -> a) -> a -> [b] -> [a] -- its type signature is the same as foldl's, but it returns a list of incremental values, instead of just the final result.
I'll leave the rest as an exercise for you, since this seems like homework. Good luck!

A:

If you are so adamant of using foldl you can do something like 
series n  = reverse $ foldl f [0] [1..n]
    where f xs@(x:_) y = x+y:xs

In ghci 
> series 5
[0,1,3,6,10,15]

But problem with foldl is you can not create infinite series. 
You can have infinite series like 
series = 0:zipWith (+) series [1..]

Then you can do something like 
> take (5+1) series
[0,1,3,6,10,15]

I have not tried but you might also use unfoldr or similar concept to build your list. 

