Intro
Col is a syntax library for OCaml for a compact and safe definition of IO functions on lists of flat records.
One type definition in a record-like syntax is expanded into a regular type definition of a record type, a tuple type and a class, plus many conversion functions which would have to be written manually otherwise. List of such objects can be loaded from and saved to CSV files with a header describing each field (column). You can edit these files manually, possibly by inserting new columns, and yet these files remain readable by your program.
See http://martin.jambon.free.fr/col-doc.html for an illustration of a program and the result after preprocessing. Hopefully it is self-explanatory. You can notice that the interface (doc.mli) which is automatically generated is much longer than the source implementation (doc.ml ~80 lines). After preprocessing, the implementation (doc.ppo) is truly huge (~800 lines), so it might take a while to compile.
Documentation
There is no documentation but there is a complete example at http://martin.jambon.free.fr/col-doc.html
Changes
version 1.1.0: added functions for custom sort. Modules which are used to define custom types must now define a comparison function named "compare" (use "let compare = compare" if you want to use OCaml's default or if you don't want to use the comparison functions).
Examples
Here is a short example which defines a list of 2 records and saves them:
(* File test.ml *)
type col t = { x : float;
y : float;
title "The Title" : string = "no title" }
let data =
let x = 1. in
[ T.create ~x ~y:2. ();
T.create ~y:4. ~x ~title:"line2" () ]
let _ = T.save_csv "data.csv" data
$ ocamlfind ocamlopt -o testcol test.ml -syntax camlp4o -package col -linkpkg
$ ./testcol
$ cat data.csv
x,y,"The Title"
1.,2.,"no title"
1.,4.,line2
$
Bugs
Installation
There is a bug in OCaml 3.09.1 which prevents from pr_o.cmo from working correctly (Stack overflow while executing something like "camlp4o pr_o.cmo ..."). The bug is not present in 3.08.4 and has been fixed in 3.09.2. If you are having this problem, compile with:
(instead of "make" alone)
Comments (0)
You don't have permission to comment on this page.