title: Pattern matching in SML - representing a list as (x::y)
body: <p>I just started learning functional programming and I find myself very confused by the concept of pattern matching (i'm using SML). Take for example the following expression to insert an element in an ordered list:</p>
  
  <pre><code>fun insert (n,nil) = [n]
    | insert (n, L as x::l) =
      if(n &lt; x) then n::L
      else x::(insert(n,l))
  </code></pre>
  
  <p>How can the list L be expressed as x::l? I know x refers to the first element of the list and l to the rest, but I don't know what to call this construct or how it can be used. I have read a lot but all the documentation I find doesn't mention this at all. Here is another example that doesn't use the 'as' keyword.</p>
  
  <pre><code>(*returns a list with the sum of each element added of two lists added together*)
  
  fun addLists (nil,L) = L
  | addLists (L,nil) = L
  | addLists (x::xs,y::ys) =
    (x + y)::(addLists(xs,ys))
  </code></pre>
  
  <p>Thank you for your help!</p>