title: How do I generate all combinations of list elements to a given length with iterate?
body: <p>I'm trying to write a function using <code>iterate</code> which should generate all combinations of the elements:</p>
  
  <pre><code>f :: [a] -&gt; [[[a]]]
  f [1,2] = 
    [ [[1] , [2]]                  -- all combinations of length 1
    , [[1,1],[1,2],[2,1],[2,2]],   -- all combinations of length 2
    , [[1,1,1],... ]               -- all combinations of length 3
    , ...                          -- and so on
    ]                              -- infinitely
  </code></pre>
  
  <p>I've tried the following approach</p>
  
  <pre><code>f :: [a] -&gt; [[[a]]]
  f list = iterate genLists list
  
  genLists :: [a] -&gt; [[a]]       
  genLists list  = [ [k] | k&lt;-list ] 
  </code></pre>
  
  <p>However, Hugs gives me the following error:</p>
  
  <pre><code>Type error in application
  *** Expression     : iterate genLists list
  *** Term           : genLists
  *** Type           : [a] -&gt; [[a]]
  *** Does not match : [[a]] -&gt; [[a]]
  *** Because        : unification would give infinite type
  </code></pre>
  
  <p>I don't really know why I get the error. Also, how can I generate those combinations using only <code>iterate</code>? I cannot import any other module since this is an assignment.</p>