title: Extracting elements from list in SML
body: <p>I'm trying to extract the given elements from a list, but I get an Match exception?</p>
  
  <p>The goal is to make my function behave like:</p>
  
  <pre><code>fun extract [#"a",#"b",#"c"] [0,1,0] = [#"a",#"b",#"a"];
  </code></pre>
  
  <p>And I'm trying to do it like this:</p>
  
  <pre><code>fun extract [] _ = []
    | extract xr (y::yr) = List.nth(xr, y) :: extract xr yr;
  </code></pre>
  
  <p>But as said, I get an </p>
  
  <pre><code>! Uncaught exception: 
  ! Match
  </code></pre>
  
  <p>Any ideas?
  Maybe theres some more List functions I could use for this?
  I've head about the curry function, which should make a function into a higher-order function, but I don't really know how that works?</p>