title: OCaml taking a list to form a list of list with constraints
body: <p>I'm trying to write a function that takes a list of binary numbers and returns a list of lists as follow: it must iterate over the initial list and can either add a nested list of <em>n</em> ones, up to <em>n-1</em> ones ending with a zero or a single zero. For example (with n = 3) :</p>
  
  <pre><code>[1;1;1;1;0;0] -&gt; [[1;1;1];[1;0];[0]]
  [1;1;1]       -&gt; [[1;1;1]]
  [1;0;0;1;1;0] -&gt; [[1;0];[0];[1;1;0]]
  </code></pre>
  
  <p>The code i have so far is</p>
  
  <pre><code>let bitListSequence binList n =
    let rec aux acc binList =
    match binList with
    | []    -&gt; acc
    | x::xs -&gt;
      let rec loop acc2 = function
        | 1 -&gt; if List.length acc2 &lt; n-1 then loop acc2::1 xs
               else aux acc2 xs
        | 0 -&gt; aux acc2::0 xs in
      aux [] acc
  </code></pre>
  
  <p>I think the logic is good but the syntax is incorrect. I'm trying to accumulate a nested list into <code>acc2</code> until a condition is met before appending it to <code>acc</code> and repeating the process until <code>binList</code> is empty.</p>