From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 63E15BC37 for ; Sun, 17 Jan 2010 00:21:53 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApcBAObYUUvRVdK2kGdsb2JhbACRJUSCGYdBPwEBAQEJCQwHEwOtNIEyhFSHDAECAwWELQQ X-IronPort-AV: E=Sophos;i="4.49,288,1262559600"; d="scan'208";a="45030626" Received: from mail-yx0-f182.google.com ([209.85.210.182]) by mail1-smtp-roc.national.inria.fr with ESMTP; 17 Jan 2010 00:21:52 +0100 Received: by yxe12 with SMTP id 12so1382744yxe.1 for ; Sat, 16 Jan 2010 15:21:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:references :in-reply-to:subject:date:message-id:mime-version:content-type :content-transfer-encoding:x-mailer:thread-index:content-language; bh=5jwPuHAs4wgW8wcEgoYxyDdx4tZOR0qsTCiUBMFxIB8=; b=C6v358ufxE1Gyjg+emRweZFqbYYRzbqwJsiHqicR73KhAmOpxbqViLJAikimeJuCoI MjjKXU/JahmSx3AqHXt7qhEK2AFqqTFYVgdEEUhZv296OF0g6Fdjuxk2gdRfQDPWJVK+ ujnpsXhctEqvfoX3oeS3TBB4Sv3jPxiwlauvI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:references:in-reply-to:subject:date:message-id:mime-version :content-type:content-transfer-encoding:x-mailer:thread-index :content-language; b=YSNgVmrBe1kPVnxIUGep8QUvQoWeR9so3/64FnQaP/QUj/zMPqDfV48RF2LETM7+7V oPbapr5C0yM76YHWtLnJCuRZ8RWDUCEY9aV0mafNPE3GnS2a7D0EpyX/nFunxezfCDHP nmT3uxl+Hfsus02gWp85WKTWk9c/wDsAXRyGg= Received: by 10.150.118.5 with SMTP id q5mr844306ybc.136.1263684111689; Sat, 16 Jan 2010 15:21:51 -0800 (PST) Received: from psr1913plus16 (adsl-63-198-183-99.dsl.snfc21.pacbell.net [63.198.183.99]) by mx.google.com with ESMTPS id 23sm1337707ywh.18.2010.01.16.15.21.49 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 16 Jan 2010 15:21:50 -0800 (PST) From: "Alexander Voinov" To: References: <4b523e9c.0d67f10a.06ab.ffffced7@mx.google.com> In-Reply-To: <4b523e9c.0d67f10a.06ab.ffffced7@mx.google.com> Subject: A syntax extension to simplify List manipulation Date: Sat, 16 Jan 2010 15:21:35 -0800 Message-ID: <003801ca9702$a72e2b30$f58a8190$@com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: AcqW+9xSs4cKIWoSRgy3F6jM0X2sEwABO5nQ Content-Language: en-us X-Spam: no; 0.00; voinov:01 syntax:01 syntax:01 voinov:01 arrays:01 printf:01 camlp:01 camlp:01 recursion:01 cvs:01 ocaml:01 runtime:01 ocaml:01 arrays:01 defines:01 Hi All, This is a syntax extension I've been using since 2003: http://www.voinov.org/FP/spbSyntax.tgz 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! Alexander