I wrote this small program and I am a bit confused about its behaviour:
main = sequence $ iterate (printAdd =<<) (pure 0)
printAdd x = do
l <- getLine
let y = x + read l
print y
pure y
I expected it to print the sum of all integers, every time I enter a new one. It does work more or less, but the accumulator is reset to 0 repeatedly. This reset happens after the first input, after the third input, after the sixth input and so on (i.e. it always works for one input more than previously).
Why does this happen?
How can I prevent it from happening?