title: F# For each element in list a, apply function to elements in list b
body: <p>Given the following set of types representing a store:</p>
  
  <pre><code>type Article    = string
  type Amount     = int
  type Price      = int
  type Desc       = Amount*Price
  type Stock      = (Article*Desc) list
  type Order      = Article * Amount
  type Status&lt;'a&gt; = Result of 'a | Error of string
  </code></pre>
  
  <p>I want to make a function which takes an <code>Order</code> and a <code>Stock</code> and returns a <code>Status&lt;Price * Stock&gt;</code>. The value of the defined function below <code>get (a,k) st</code> is <code>Result (p,st')</code> where <code>p</code> is the price of <code>k</code> pieces of <code>a</code> and <code>st'</code> is the new stock obtained from <code>st</code> by removal of <code>k</code> pieces of <code>a</code>.</p>
  
  <p>Example:</p>
  
  <pre><code>let rec get (a,k) st =
      match st with
      | (a',(n',p'))::rest when a'=a -&gt; Result (p'*k,(a',(n'-k,p'))::rest)
      | (a',(n',p'))::rest           -&gt; 
          match get (a,k) rest with
          | Result (price,stock) -&gt; Result (price,(a',(n',p'))::stock)
          | Error e              -&gt; Error e
  
  get ("a2", 10) st
  val it : int * (string * (int * int)) list =
    Result (200, [("a1", (100, 10)); ("a2", (40, 20)); ("a3", (25, 40))])
  </code></pre>
  
  <p>Now, how would I go about doing this if I took an <code>Order list</code>? </p>
  
  <p>Such as <code>get [("a2",10);("a1",10)] st</code> would return <code>Result (300, [("a1", (90, 10)); ("a2", (40, 20)); ("a3", (25, 40))])</code></p>