title: Pattern matching against a tuple in the IO Monad in Haskell
body: <p>I've been studying Haskell in my spare time and have recently crossed into the area of monadic functions. I've distilled the code from an excercise I've been working on into this very contrived example to isolate the exact problem I'm having:</p>
  
  <pre><code>import System.Random
  
  rndPermu :: [a] -&gt; IO (a, [a])
  rndPermu xs = (front, back)
      where (front, back) = hurf xs
  
  hurf :: [a] -&gt; IO (a, [a])
  hurf xs = randomRIO (0, (length xs) - 1) &gt;&gt;= \r -&gt; return $ removeAt r xs
  
  removeAt :: Int -&gt; [a] -&gt; (a, [a])
  removeAt n xs = (e, rest)
      where e    = xs !! n
            rest = take n xs ++ (tail $ drop n xs)
  </code></pre>
  
  <p>rndPermu produces a type error when loaded into GHCi stating a type (t, t1) was expected in the 'where' clause but IO (a, [a]) was received. I can use things like (liftM fst) to pull individual items from the tuple and just assign a single value but that's obviously a sloppy and roundabout way of going about things. I feel I'm probably stumbling over some minor nuance of syntax that's staring me in the face. How does one resolve this type error? It should be possible to directly match against a tuple wrapped in a monad, shouldn't it?</p>