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
Configuring emacs to work with caml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2010-01-16 (23:21)
From: Alexander Voinov <avoinov@g...>
Subject: A syntax extension to simplify List manipulation
Hi All,

This is a syntax extension I've been using since 2003:


It defines a number of constructs, which make List traversals look like
loops over arrays/sequences in popular languages like Python:

map [1;2;3] with e -> e + 1

filtermap [1;2;3] with e when e mod 2 == 0 -> Some e | _ -> None

foldl [1;2;3] from 0 with s0, e -> s0 + e

iterate [1;2;3] with e -> printf "%d\n" e done

and some more like this.

It relies upon camlp5 instead of (new) camlp4. It maps those constructs into
the corresponding functions of ExtLib (not the standard List module), so
that one can use tail recursion optimization.

The motivation to this syntax extension was as follows. I've been working in
bioinformatics and we have had ~10000000 lines of Python code in our CVS.
I've started to use OCaml for some applications where I needed more runtime
speed than Python could deliver and still didn't want to dive into C++. Also
I tried to promote OCaml among my Pythonic colleagues. That is why I enjoyed
a possibility to make list processing constructs looking like Python loops
over lists (that is, dynamic arrays). I've identified a number of common use
cases and mapped each of them onto an appropriate higher order function from
the Extlib library. On the caml side, these extensions look similar to the
match ... with construct.

An example code, included into the distribution show how I've been and still
am using these extensions in practical applications.

Thank you!