title: How do I monad an arbitrary number of Monads together in Haskell?
body: <p>Let's say I have</p>
  
  <pre><code>x :: Monad a =&gt; [a]
  x = [item1, item2, item3, ...]
  </code></pre>
  
  <p>And I want to do for these:</p>
  
  <pre><code>y f = f &lt;$&gt; item1 &lt;*&gt; item2 &lt;*&gt; item3 &lt;*&gt; item4 &lt;*&gt; ...
  </code></pre>
  
  <p>Previously I've tried this for doing it with ZipLists:</p>
  
  <pre><code>zipf' x (y:z) = getZipList $ foldl (&lt;*&gt;) (x &lt;$&gt; y) z
  </code></pre>
  
  <p>But it unfortunately returned this:</p>
  
  <pre><code>&lt;interactive&gt;:94:36: error:
  • Occurs check: cannot construct the infinite type: a1 ~ a -&gt; a1
    Expected type: ZipList a1 -&gt; ZipList a -&gt; ZipList a1
      Actual type: ZipList (a -&gt; a1) -&gt; ZipList a -&gt; ZipList a1
  • In the first argument of ‘foldl’, namely ‘(&lt;*&gt;)’
    In the second argument of ‘($)’, namely ‘foldl (&lt;*&gt;) (x &lt;$&gt; y) z’
    In the expression: getZipList $ foldl (&lt;*&gt;) (x &lt;$&gt; y) z
  • Relevant bindings include
      z :: [ZipList a] (bound at &lt;interactive&gt;:94:12)
      y :: ZipList a (bound at &lt;interactive&gt;:94:10)
      x :: a -&gt; a1 (bound at &lt;interactive&gt;:94:7)
      zipf' :: (a -&gt; a1) -&gt; [ZipList a] -&gt; [a1]
        (bound at &lt;interactive&gt;:94:1)
  </code></pre>