English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
announcement - Col: from records to CSV and vice-versa
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-04-27 (07:47)
From: Martin Jambon <martin_jambon@e...>
Subject: announcement - Col: from records to CSV and vice-versa
Col is a syntax library for the conversion between lists of records and 
CSV files with header. CSV (Comma-Separated Values) is a text format 
supported by spreadsheet programs. "records" are represented as OCaml 
records, tuples or objects, all being available and interconvertible.

   main URL: http://martin.jambon.free.fr/ocaml.html#col
   development/discussion wiki: http://ocaml.pbwiki.com/Col

For a demonstration of what the syntax can do, see

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
(* end *)

$ ocamlfind ocamlopt -o testcol test.ml -syntax camlp4o -package col -linkpkg
$ ./testcol
$ cat data.csv
x,y,"The Title"
1.,2.,"no title"

This package is not well-documented but I have been using it intensively 
with openoffice.org and gnuplot, and it is stable. My largest record type 
has 49 fields and is still growing!

Have fun!

Martin Jambon, PhD

Edit http://wikiomics.org, bioinformatics wiki