title: How to generate an infinite list in Haskell based on two inputs?
body: <p>I need to generate an infinite list based on two inputs.</p>
  
  <pre><code>gen :: Int -&gt; Int -&gt; [Int]
  gen x y
  </code></pre>
  
  <p>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</p>
  
  <pre><code>gen 2 4
  </code></pre>
  
  <p>would result in</p>
  
  <pre><code>[2,8,24,40,..]
  </code></pre>
  
  <p>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. </p>
  
  <p>EDIT</p>
  
  <p>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. </p>
  
  <pre><code>gen :: Int -&gt; Int -&gt; [Int]
  gen x y = 
   do 
    a &lt;- [x..]
    guard $ mod a (x*y) == 0
    let x = x+y
    return a
  </code></pre>