title: Problems with understanding splitAt in Haskell?
body: <p>So I have found that the built-in splitAt function in Haskell can be defined as follows:</p>
  
  <pre><code>splitAt :: Int -&gt; [a] -&gt; ([a], [a])
  -- Pre: n &gt;= 0
  splitAt n []
      = ([], [])
  splitAt n (x : xs)
      = if n == 0
        then ([], x : xs)
        else (x : xs', xs'')
    where
      (xs', xs'') = splitAt (n - 1) xs
  </code></pre>
  
  <p>What I don't understand here/can't get my head around is the where part.</p>
  
  <p>As an example,</p>
  
  <p><code>splitAt 2 "Haskell"</code> should return <code>(["Ha"],["skell"])</code>, but I don't really understand how it works here to define <code>(x:xs',xs'')</code> as another function? How would this look like visually?</p>
  
  <p>With the example:</p>
  
  <pre><code>splitAt 2 "Haskell"
    = (('H':xs',xs'')) 
  </code></pre>
  
  <p>^ so this then does <code>splitAt 1 "askell"</code>, but I'm very confused as to what happens to the <code>xs',xs''</code> in the tuple above...</p>
  
  <p>Thanks.</p>