title: OCaml Function that takes in functions
body: <p>I need to write a <code>pipe</code> function in OCaml such  that <code>pipe [f1;...;fn]</code> (where <code>f1</code>,...,<code>fn</code> are functions!) returns a function <code>f</code> such that for any x, <code>f x</code> computes <code>fn(...(f2(f1 x)))</code>.</p>
  
  <p>I need to write it using <code>List.fold_left</code> and need to fill in the parameter of the function</p>
  
  <pre><code>let pipe fs =
     let f a x = "fill in this part" in
     let base = fun x -&gt;x in
     List.fold_left f base fs;;
  </code></pre>
  
  <p>I already filled in the base. If the first parameter to pipe is an empty list, it returns the second parameter. Ex: pipe [] 3 = 3.
  i know for the let f a x part I want to perform function x of the accumulated functions a.
  I'm just not sure how to write that.  I wrote let f a x = x a but that gave me an error when i tested 
  pipe [(fun x -> x+x); (fun x -> x + 3)] 3</p>
  
  <p>it should run x+x on 3 then run x+3 on the result and give me 9 but it gave it a type error when i tried to use let f a x = x a 
  for the fill in part</p>
  
  <pre><code># let _ = pipe [(fun x -&gt; x+x); (fun x -&gt; x + 3)] 3;;
  File "", line 1, characters 24-25:
  
  Error: This expression has type 'a -&gt; 'a
         but an expression was expected of type int 
  </code></pre>
  
  <p>What is the correct format to create a function that takes in 2 functions and runs them on each other. Ex: make a function that takes in functions a and b and runs b on the result of a.</p>