title: To convert a a string list list to an string array array in OCaml
body: <p>I'm trying to get a pretty print function to print the query result of my database in OCaml. I've been following this approach <a href="http://mancoosi.org/~abate/ocaml-format-module" rel="nofollow">http://mancoosi.org/~abate/ocaml-format-module</a> </p>
  
  <p>I have this code so far:</p>
  
  <pre><code>let pp_cell fmt cell = Format.fprintf fmt "%s" cell;;
  
  let pp_header widths fmt header =
    let first_row = Array.map (fun x -&gt; String.make (x + 1) ' ') widths in
    Array.iteri (fun j cell -&gt;
      Format.pp_set_tab fmt ();
      for z=0 to (String.length header.(j)) - 1 do cell.[z] &lt;- header.(j).[z] done;
      Format.fprintf fmt "%s" cell
    ) first_row
  
  let pp_row pp_cell fmt row =
    Array.iteri (fun j cell -&gt;
      Format.pp_print_tab fmt ();
      Format.fprintf fmt "%a" pp_cell cell
    ) row
  
  
  let pp_tables pp_row fmt (header,table) =
    (* we build with the largest length of each column of the 
     * table and header *)
    let widths = Array.create (Array.length table.(0)) 0 in
    Array.iter (fun row -&gt;
      Array.iteri (fun j cell -&gt;
        widths.(j) &lt;- max (String.length cell) widths.(j)
      ) row
    ) table;
    Array.iteri (fun j cell -&gt;
      widths.(j) &lt;- max (String.length cell) widths.(j)
    ) header;
  
    (* open the table box *)
    Format.pp_open_tbox fmt ();
  
    (* print the header *)
    Format.fprintf fmt "%a@\n" (pp_header widths) header;
    (* print the table *)
    Array.iter (pp_row fmt) table;
  
    (* close the box *)
    Format.pp_close_tbox fmt ();
  ;;
  
  
  (** Pretty print answer set of a query in format of
   *    col_name 1 | col_name 2 | col_name 3 |
   *    result1.1  | result2.1  | result3.1  |
   *    result1.2  | result2.2  | result3.2  |
   *   @param col_names provides the names of columns in result outp ut *)
  let pretty_print fmt pp_cell (col_names, tuples) =
      match col_names with
    | [] -&gt; printf "Empty query\n"
    | _ -&gt;
          printf "Tuples ok\n";
          printf "%i tuples with %i fields\n" (List.length tuples) (List.length col_names);
          print_endline(String.concat "\t|" col_names);
          for i = 1 to List.length col_names do printf "--------" done; print_newline() ;
          let print_row = List.iter (printf "%s\t|") in
          List.iter (fun r -&gt; print_row r ; print_newline ()) tuples;
          for i = 1 to List.length col_names do printf "--------" done; print_newline() ;
  
      let fmt = Format.std_formatter in
      Format.fprintf fmt "%a" (pp_tables (pp_row pp_cell)) (Array.of_list col_names,tuples);
  
        flush stdout
  ;;
  
  let print_res (col_names, tuples) =
      let fmt = Format.std_formatter in
      pretty_print fmt pp_cell (col_names, tuples)
  ;;
  </code></pre>
  
  <p>The problem is in the line </p>
  
  <pre><code>Format.fprintf fmt "%a" (pp_tables (pp_row pp_cell)) (Array.of_list col_names,tuples);
  </code></pre>
  
  <p>basically because I need tuples to be and string array array (a matrix) while its type is string list list. So I tried to solve it by converting the list list into a matrix following this approach <a href="http://www.siteduzero.com/forum-83-589601-p1-ocaml-convertir-un-list-list-en-array-array.html" rel="nofollow">http://www.siteduzero.com/forum-83-589601-p1-ocaml-convertir-un-list-list-en-array-array.html</a> with this code:</p>
  
  <pre><code>let listToMatrix lli =
    let result = Array.init 6 (fun _ -&gt; Array.create 7 2)
    let rec outer = function
      | h :: tl, col -&gt;
        let rec inner = function
          | h :: tl, row -&gt;
            result.[row].[col] &lt;- h
            inner (tl, row + 1)
          | _ -&gt; ()
  
        inner (h, 6 - List.length h)
        outer (tl, col + 1)
      | _ -&gt; ()
    outer (lli, 0)
    result
  ;;
  </code></pre>
  
  <p>But I  just a syntax error while compiling:</p>
  
  <pre><code>File "src/conn_ops.ml", line 137, characters 2-5:
  Error: Syntax error
  make: *** [bin/conn_ops.cmo] Error 2
  </code></pre>
  
  <p>I don't really know what to do, or how I can accomplish the conversation of the list list into the matrix. My approach is the correct? This has been the first time I've worked with OCaml and it's been quite a pain in the <em>*</em>, so please, try to be kind with me :D </p>