title: Mixing fmap and bind (>>=)
body: <p>In Haskell, when I have to mix calls to <code>fmap</code>/<code>&lt;$&gt;</code> and <code>&gt;&gt;=</code>/<code>=&lt;&lt;</code>, I invariably end up with lots of parenthesis.</p>
  
  <p>For example, here I'm calling <code>listDirectoryAbs dir :: IO [String]</code> and then chaining a series of <code>filter</code> and <code>filterM</code>, ending with a <code>fmap</code>.</p>
  
  <pre><code>findDlls :: String -&gt; IO [String]
  findDlls dir = f &lt;$&gt; (filterM predicate1 =&lt;&lt; (filter predicate2 &lt;$&gt; (filterM predicate3 =&lt;&lt; listDirectoryAbs dir)))
  </code></pre>
  
  <p>Because all these nested expressions look messy (at least to me), I end up rewriting <code>f &lt;$&gt; x</code> to <code>return . f =&lt;&lt; x</code>. If I then flip the binds, I get something more readable:</p>
  
  <pre><code>findDlls dir = listDirectoryAbs dir
   &gt;&gt;= filterM predicate3
   &gt;&gt;= return . filter predicate2
   &gt;&gt;= filterM predicate1
   &gt;&gt;= return . f
  </code></pre>
  
  <p>Is rewriting <code>f &lt;$&gt; x</code> -> <code>return . f =&lt;&lt; x</code> -> <code>x &gt;&gt;= return . f</code> "bad" in any way? Is there a preferable way of avoiding nested expressions in situations such as these?</p>
  
  <p>I <em>could</em> use <code>do</code> notation instead, but I'd like to avoid having to be explicit about data flow and giving every return value a name.</p>