I need to generate an infinite list based on two inputs.
gen :: Int -> Int -> [Int]
gen x y
Every element needs to be (x*y) and x is incremented by y each iteration and the original x must be in the list too. So
gen 2 4
would result in
[2,8,24,40,..]
All of my attempts end up going forever (I use the call "take 4 (gen 2 4)" by in ghci the way) so I'm not sure how to proceed. Infinite lists just give me a lot of trouble. I'm trying to do this through do-notation and the list monad. Any help in the right direction would be much appreciated.
EDIT
This was my last attempt which didnt work. I'm learning Haskell through my friend and he gave me this problem to learn do notation for the list monad.
gen :: Int -> Int -> [Int]
gen x y =
do
a <- [x..]
guard $ mod a (x*y) == 0
let x = x+y
return a