title: What's wrong with my recursive list construction?
body: <p>I've simplified the functions in question. I'm having trouble constructing a list inside a monad. I suspect a precedence problem.</p>
  
  <pre><code>newtype Boundary = MkBoundary Integer
  
  testFunc :: [Boundary] -&gt; [Maybe Integer]
  testFunc (MkBoundary x:xs)
     | (even x) = Just x : testFunc xs
     | otherwise = Nothing : testFunc xs
  testFunc _ = []
  </code></pre>
  
  <p>This works as expected. But I need to work in a monad. I'll use IO for this example</p>
  
  <pre><code>testFunc :: [Boundary] -&gt; IO [Maybe Integer]
  testFunc (MkBoundary x:xs)
     | (even x) = return $ Just x : testFunc xs
     | otherwise = return $ Nothing : testFunc xs
  testFunc _ = []
  </code></pre>
  
  <p>No matter how I try to manipulate precedence, this breaks. </p>
  
  <pre><code>test.hs:6:35:
      Couldn't match expected type `[Maybe Integer]'
                  with actual type `IO [Maybe Integer]'
      In the return type of a call of `testFunc'
      In the second argument of `(:)', namely `testFunc xs'
      In the second argument of `($)', namely `Just x : testFunc xs'
  Failed, modules loaded: none.
  </code></pre>
  
  <p>What I am trying to accomplish is a constructing a list, then returning it to IO. What am I doing wrong?</p>