title: couldn't match expected type
body: <p>I would like to do something different but it would be too long so below is only example:</p>
  
  <pre><code>test x y = if x == "5" then x
             else do putStrLn "bad value"; y
  </code></pre>
  
  <p>so if x == 5 it should return x, else it should print 'bad value' and return y - how can I do that in haskell ?</p>
  
  <hr>
  
  <p><strong>edit:</strong></p>
  
  <p>Why this code returns error: "couldn't match expected type bool with actual type IO bool" ?</p>
  
  <pre><code>canTest :: String -&gt; IO Bool
  canTest x = if x == "5" then return True
             else do putStrLn "bad value"; return False
  
  test x y = if canTest x then x
             else y
  </code></pre>