title: Error in code to flatten a list in Ocaml
body: <p>Hello All I am trying to flatten a list in Ocaml. I am a newbie so please pardon me if my mistake is dumb</p>
  
  <p>So for example, if input is [[1];[2;3];[4]]  I should end up with [1;2;3;4]. </p>
  
  <p>The idea I am trying to use is as follows
  Iterate through the list from the right (Using fold_right) with accumaltor = []
  The pseudo code is as follows</p>
  
  <pre><code>func flatten(list,  accumalator) 
    For each item from right to left in list 
       If Item is a scalar then n :: accumalator
       Else fi Item is a list of form head :: tail then
                 head :: flatten (tail, accumalator).
  </code></pre>
  
  <p>I think that theoretically the algorithm is correct, but please let me know if you disagree.</p>
  
  <p>Now to my OCaml code to implement this algorithm</p>
  
  <pre><code>let rec flatten acc x =
      match x with 
             n -&gt; n :: acc
          | [x] -&gt; x :: acc
          | head :: remainder -&gt; 
              head :: ( my_flat acc remainder ) 
   and my_flat = List.fold_right flatten
   ;;
  
   my_flat [] [[1];[2;3];[4]]
  </code></pre>
  
  <p>The Error I get is the following
       Error: This expression has type 'a but an expression was expected of type
           'a list</p>
  
  <p>The error occurs on the line that reads head :: ( my_flat acc remainder )  in the last pattern in the match statement</p>
  
  <p>Any help is appreciated.</p>