title: How does as work in ocaml?
body: <p>I was writing a function that inserts a integer at the nth spot in a list and I initially wrote </p>
  
  <pre><code> let rec insert x n l =
   match l with
   |[] -&gt; [x]
   | h:: t -&gt; if n = 0 then x :: l else h :: insert x (n-1) t
  </code></pre>
  
  <p>this would throw an error when I tried to add an integer at the end of the list.</p>
  
  <pre><code>let rec insert x n l =
  match l with
   |[] -&gt; [x]
   |h :: t as l  -&gt; if n = 0 then x :: l else h :: insert x (n-1) t
           _
  </code></pre>
  
  <p>Adding as fixed the problem but I am not sure I fully understand what as is doing and was wondering how else as could be used.</p>