title: Couldn't match expected type `IO ()' with actual type `a0 -> m0 a0'
body: <p>Here's my code:</p>
  
  <pre><code>doSomething :: IO Bool -&gt; IO () -&gt; IO ()
  doSomething cond body = cond &gt;&gt;= ( \condition -&gt; if condition then return else body )
  </code></pre>
  
  <p>It gives me this error:</p>
  
  <pre><code>Couldn't match expected type `IO ()' with actual type `a0 -&gt; m0 a0'
  In the expression: return
  In the expression: if condition then return else body
  In the second argument of `(&gt;&gt;=)', namely
    `(\ condition -&gt; if condition then return else body)'
  </code></pre>
  
  <p>I also tried this equivalent notation:</p>
  
  <pre><code>whileM :: IO Bool -&gt; IO () -&gt; IO ()
  whileM cond body = do
                       condition &lt;- cond
                       if condition then return else body
  </code></pre>
  
  <p>but I am getting more or less the same notation. I understand that the error is saying that the function expects me to return a Monad but instead I am returning a function which transforms <code>a0</code> into a monad <code>m a0</code>. How can I fix this?</p>