title: Difficulty with recursive list-splitting function in F#
body: <p>I'm trying to implement a function used to split a list into two equal-length halves (the problem assumes the list is of even length) in F#. Using the search function yielded a thread that deals with the exact same problem I'm trying to work through now:</p>
  
  <p><a href="https://stackoverflow.com/questions/4866640/split-list-into-two-equal-lists-in-f">Split list into two equal lists in F#</a></p>
  
  <p>I'm trying to implement the solution given by the user Juliet, who provides a partial answer:</p>
  
  <pre><code>let cut l =
  let rec cut = function
      | xs, ([] | [_]) -&gt; xs
      | [], _ -&gt; []
      | x::xs, y::y'::ys -&gt; cut (xs, ys)
  cut (l, l)
  </code></pre>
  
  <p>Which returns the second half of the list. I'm trying to work out a way to return the first half, so I made some modifications:</p>
  
  <pre><code>let rec cut(xs, ys) =
  let zs = []
  match xs, ys with
      | xs, ([] | [_]) -&gt; (xs, zs)
      | [], _ -&gt; ([], [])
      | x::xs, y1::y2::ys -&gt; 
          x::zs
          cut (xs, ys)
  </code></pre>
  
  <p>You can probably tell that F# is my first functional programming language, and I'm kinda confused as to how it works, exactly. Pattern-matching is a new thing for me, and I was never very good at recursion to start with.</p>
  
  <p>From what I understand, the way pattern matching works is that it's basically a more versatile version of an if-then-else statement, where the code to the left of the -> is the conditional (the "if" bit), and everything to the right is the block of code to execute if the conditional check passes (the "then" bit).</p>
  
  <p>What I'm not totally sure of is whether you're allowed to do things like this:</p>
  
  <pre><code>| x::xs, y1::y2::ys -&gt; 
          x::zs
          cut (xs, ys)
  </code></pre>
  
  <p>If pattern matching really does work like if statements, then it should be, since in an if statement it would look something like</p>
  
  <pre><code> if (x::xs &amp;&amp; y1::y2::ys)
         {
           x::zs
           cut (xs, ys)
         }
  </code></pre>
  
  <p>Anyhow, it doesn't seem like the statement x::zs is allowed, since Visual Studio gives me a warning:</p>
  
  <blockquote>
    <p>The result of this expression is implicitly ignored. Consider using "ignore" to discard this value explicitly, e.g. 'expr |> ignore', or 'let' to bind the result to a name, e.g. let result = expr'.</p>
  </blockquote>
  
  <p>I'm not sure what it means by that last part. I thought I had already declared the list as a local variable of the function in the line</p>
  
  <pre><code>let zs = []
  </code></pre>
  
  <p>All I'm trying to do is take the head of the list xs in each recursive iteration of the cut function and add it to another list zs, which when the base case is reached, would contain every element x passed over (in other words, the first half of the list), then return both xs (which contains the second half of the list) and the list containing the first half, but it doesn't seem like that's allowed?</p>