title: Looping over a function in Haskell
body: <p>I'm just puzzled with this one, it's a Haskell loop-sort-of-thing which I can't figure out how to write. Basically, I've defined three functions <b>split</b>, <b>riffle</b> and <b>shuffle</b>.</p>
  
  <pre><code>split :: [a] -&gt; ([a],[a])
  split xs = splitAt (length xs `div` 2) xs
  
  riffle :: [a] -&gt; [a] -&gt; [a]
  riffle xs [] = xs
  riffle [] ys = ys
  riffle (x:xs) (y:ys) = x:y:riffle xs ys
  
  shuffle :: Int -&gt; [a] -&gt; [a]
  shuffle 0 xs = xs
  shuffle n xs = shuffle (n-1) (riffle a b)
      where (a, b) = split xs 
  </code></pre>
  
  <p>Basically split just splits a list in half, riffle is supposed to 'interlace' two lists, so for example:</p>
  
  <pre><code>riffle [1,2,3] [4,5,6] = [1,4,2,5,3,6]
  </code></pre>
  
  <p>And shuffle is to iterate the amount of splitting and riffling of the list items. Now I need to define a function <b>repeats</b> which outputs how many iterations of shuffle would it take to get the original list again. The function is defined as such:</p>
  
  <pre><code>repeats :: [Int] -&gt; Int
  </code></pre>
  
  <p>I'm just stuck as to how you can perform a loop over the shuffle... I think it has something to do with list comprehension but I couldn't get anything. I have yet to try a lambda expression but I don't think it's necessary. By the way, the shuffle should be done on lists with even number of items. Any ideas?</p>