My question is :
I have a list and a number and I want to sum the number to the list so I can do this
Adding ls n = [x+n| x<-ls]
and it works.
My question is I want to add n+1, n+2, n+3 depending of the length of the list.
If I do
let b = 0
Adding´ ls n = [x+adder n b| x<-ls] where adder n b= n+b,b++
it doesn't work because the b doesn't advance, so if I have Adding´ [1,3,4] 3 = [4,7,9] .
You may use
Data.List.mapAccumL(mapAccumL :: Traversable t => (a -> b -> (a, c)) -> a -> t b -> (a, t c)) to achieve this task.The first parameter is a function which takes two parameters
a(accumulator) andn(the list item) and returns a tuple. In our case we incrementa(the accumulator) by 1 and map the current elementnby adding the accumulator. The result is a tuple in which the first item is the final state of the accumulator and the second is the final state of the list. We extract the second item bysnd.