Ocaml syntax error expecting single int if statemnts with pattern matching
<p>When I run the code shown below I get an error that I have also shown below and i am unsure why this is happening </p>

<pre><code>let average x y = ((x+y)/2);;



let rec average2 xs = function

| [x,y] -&gt; average x y :: xs

| x :: y :: xs -&gt; if xs = [] then average x y :: xs else average2 xs;;



Error: This expression has type int * int but an expression was expected of type int  
</code></pre>

<p>The letter x in the last line is underlined by this error though when defining the average function it should be retruning just an int to add to the xs list</p>

<p>Thanks for any help</p>