title: Haskell list comprehension - list of all list splits
body: <p>I've just wanted to write a function <code>splits</code> that takes a list <code>l</code> and returns a list of tuples that contain all possible ways to split <code>l</code>.</p>
  
  <p>So it should work like this:</p>
  
  <pre><code>splits "Hello"
  [("","Hello"),("H","ello"),("He","llo"),("Hel","lo"),("Hell","o"),("Hello","")]
  </code></pre>
  
  <p><strong>Implementation 1</strong> What I wrote is this:</p>
  
  <pre><code>splits l = [(x,y) | i &lt;- [0 ..length l], x &lt;- take i l, y &lt;- drop i l]
  </code></pre>
  
  <p>which gives</p>
  
  <pre><code>[('H','e'),('H','l'),('H','l'),('H','o'),('H','l'),('H','l'),('H','o'),
   ('e','l'),('e','l'),('e','o'),
   ('H','l'),('H','o'),
   ('e','l'),('e','o'),
   ('l','l'),('l','o'),
   ('H','o'),('e','o'),('l','o'),('l','o')]
  </code></pre>
  
  <p><strong>Implementation 2</strong> The correct solution is</p>
  
  <pre><code>splits l = [(take i l, drop i l) | i &lt;- [0 ..length l]]
  </code></pre>
  
  <p><strong>Question</strong>: Why are implementation 1 and implementation 2 doing different things? What's going on in implementation 1?</p>