title: generate infinite list of RandomGen
body: <p>I want to apply a function f which needs a RandomGen over a list. I tried to generate me therefore a infinite list of RandomGen as you can see below. (just random values as generated by the function "randoms" isn't sufficient, because the needed range of the value depends on the input for f.)</p>
  
  <pre><code>module Test where
  import System.Random (getStdGen, RandomGen, randomR, random)
  
  f :: (RandomGen g, Integral a) =&gt; g -&gt; a -&gt; Bool
  
  randomGens :: RandomGen g =&gt; g -&gt; [g]
  randomGens gen =
    let (i, gen') = (random gen) :: (Int, g1)
    in  gen : (repeatGen gen')
  </code></pre>
  
  <p>Unfortunately the compiler tells me, that it fails</p>
  
  <pre><code>Test.hs:13:26:
      Could not deduce (g1 ~ g)
      from the context (RandomGen g)
        bound by the type signature for
               randomGens :: RandomGen g =&gt; g -&gt; (g, g)
        at Test.hs:11:14-39
      or from (RandomGen g1)
        bound by an expression type signature: RandomGen g1 =&gt; (Int, g1)
        at Test.hs:13:19-55
        `g1' is a rigid type variable bound by
             an expression type signature: RandomGen g1 =&gt; (Int, g1)
             at Test.hs:13:19
        `g' is a rigid type variable bound by
        the type signature for randomGens :: RandomGen g =&gt; g -&gt; (g, g)
            at Test.hs:11:14
      In the first argument of `random', namely `gen'
      In the expression: random gen :: RandomGen g =&gt; (Int, g)
      In a pattern binding:
        (i, gen') = random gen :: RandomGen g =&gt; (Int, g)
  </code></pre>
  
  <p>Just skipping in the let-binding the type annotation (Int, g1) doesn't work. He needs to have the result-type for the application of "random"</p>