title: F# pattern-matching gone wrong
body: <p>I am just starting out with F# so this might be a trivial question but I am not able to understand why the pattern matching in my code acts as it does.</p>
  
  <p>Quick explanation of the code:<br>
  The func <strong>calcNextMatch</strong> should recurse a list and if 2 elements are equal they should be added together.
  In the end the func should return a number that is the addition of all digits that has a match with the next digit in the list.<br>
  f.ex. [1;3;2;2;5] should return 4   </p>
  
  <p>Code:</p>
  
  <pre><code>let rec printList l =
      match l with
      | head :: tail -&gt; printf "%d " head; printList tail
      | [] -&gt; printfn ""
  
  let rec calcNextMatch list =
      printList list
      match list with
      | [] -&gt; 0
      | _ :: tail -&gt;            
          printList tail
          let h = Seq.head list
          let t = Seq.tryHead tail
          printfn "h: %i" h
          printfn "t: %O" t
          match t with
          | Some h -&gt; 
              printfn "TAIL t: %i is equal to HEAD h: %i" t.Value h
              printfn "Calculation is: %i" (t.Value + h)
              (t.Value + h) + calcNextMatch tail
          | _ -&gt; calcNextMatch tail
  
  let sequence = [ 1;3;2;2;5 ]
  let run = calcNextMatch sequence
  </code></pre>
  
  <p>When I run this code the problem is that the pattern-matching 
  does not work as I expect it.
  f.ex this print output from running the script.</p>
  
  <pre><code>h: 1
  t: Some(3)
  TAIL t: 3 is equal to HEAD h: 3
  </code></pre>
  
  <p>this means that F# has matched</p>
  
  <pre><code>match t with
          | Some h -&gt; 
  </code></pre>
  
  <p>in a case where t = Some(3) and h = 1
  which translates to</p>
  
  <pre><code>match 3 with
          | Some 1 -&gt; 
  </code></pre>
  
  <p>and that I do not understand.
  The print before the matching states the value of t and h to <strong>3</strong> and <strong>1</strong> but in the pattern-matching the value of <strong>h</strong> has change to <strong>3</strong><br>
  How is this possible?</p>