title: Haskell - Need help understanding this split function
body: <p>I need help understanding the following Haskell function, </p>
  
  <pre class="lang-hs prettyprint-override"><code>split l = rr++[ll]
              where
                split = foldl
                          ( \ (c,a) e -&gt;
                                 case c of
                                  [] -&gt; ([e],a)  
                                  _ -&gt; if e*(head c) &lt; 0
                                       then ([e],a++[c])
                                       else (c++[e],a))
                          ([],[])
                (ll,rr) = split l
  
  &gt; split [1,2,3,-1,-2,7,4,-3,-5,-6,2,3]
  [[1,2,3],[-1,-2],[7,4],[-3,-5,-6],[2,3]]
  </code></pre>
  
  <p>It splits consecutive numbers with the same sign in separate lists as seen above. In Scheme, the tracer function was so helpful in evaluating expressions step by step, but unfortunately, GHCi doesn't have such a feature. Please help me step through the code. Thanks!</p>
  
  <p>Note: I understand the foldl part of the function. It is the pattern matching part (<code>split l = rr++[ll]</code> and <code>(ll,rr) = split l</code>) which really confuses me!</p>