From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 3A35B7F86A for ; Mon, 10 Mar 2014 10:18:04 +0100 (CET) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of arnaud.spiwack@gmail.com) identity=pra; client-ip=74.125.82.176; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="arnaud.spiwack@gmail.com"; x-sender="arnaud.spiwack@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of arnaud.spiwack@gmail.com designates 74.125.82.176 as permitted sender) identity=mailfrom; client-ip=74.125.82.176; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="arnaud.spiwack@gmail.com"; x-sender="arnaud.spiwack@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-we0-f176.google.com) identity=helo; client-ip=74.125.82.176; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="arnaud.spiwack@gmail.com"; x-sender="postmaster@mail-we0-f176.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApECAAKDHVNKfVKwlWdsb2JhbABag0FXgwaoH5YXgRMIFg4BAQEBBw0JCRIqgiUBAQEDAQEBASAEGQEtCwEDAQsBBQUEBzcCAiIFAQwBBQEcBhOHZQMJCA2iJ4wOg1+VcScNhwcRAQUMjWdkgnqBSQSVboJXgTKPDRgpgWaCdTw X-IPAS-Result: ApECAAKDHVNKfVKwlWdsb2JhbABag0FXgwaoH5YXgRMIFg4BAQEBBw0JCRIqgiUBAQEDAQEBASAEGQEtCwEDAQsBBQUEBzcCAiIFAQwBBQEcBhOHZQMJCA2iJ4wOg1+VcScNhwcRAQUMjWdkgnqBSQSVboJXgTKPDRgpgWaCdTw X-IronPort-AV: E=Sophos;i="4.97,622,1389740400"; d="scan'208";a="62073162" Received: from mail-we0-f176.google.com ([74.125.82.176]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 10 Mar 2014 10:17:57 +0100 Received: by mail-we0-f176.google.com with SMTP id x48so8027347wes.7 for ; Mon, 10 Mar 2014 02:17:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=vLSRUg8lHzEu8IzVcQnbNRjmLG7xqZrCF8vcwq/Np7g=; b=yyhj7oJ0Q3AjKWkQ6GE32l0SHMTCfN0cK5SmwZz/8CjNuWjd1l463CDR/SKFq5ckbf +v/Id07R2GJhoKwz/Do4JAjOw2yFAXr8h+AM/l0MxqomQdW06ehVRSr4X8qL3uhUFoxV FA/70RUJB5GPo0PzAyJ0LhEN25WrPfk6oyA2GQjAiyy1rYo/eG7V6VD26dCgZaoWof8k G/kRF4h5uXPKSHqPVL57HnW6NdgPDhFpyYLqq95FcLF80SBlFQWmoIBYKxa6QnWRI3AN x2OcyHSO5mN1TXtzVhvv5aCtWXW0uL1Renk3BBL2NC4G6AkFwCpCxhXrhmMVK3jT7az7 Y9Zw== X-Received: by 10.180.219.44 with SMTP id pl12mr7219840wic.12.1394443076856; Mon, 10 Mar 2014 02:17:56 -0700 (PDT) MIME-Version: 1.0 Sender: arnaud.spiwack@gmail.com Received: by 10.216.21.70 with HTTP; Mon, 10 Mar 2014 02:17:16 -0700 (PDT) In-Reply-To: <20140307221234.GA14634@lenat> References: <20140307221234.GA14634@lenat> From: Arnaud Spiwack Date: Mon, 10 Mar 2014 10:17:16 +0100 X-Google-Sender-Auth: 7mztagtAThwGEYOLZaW--nZc54g Message-ID: To: Simon Cruanes Cc: Yotam Barnoy , Ocaml Mailing List Content-Type: multipart/alternative; boundary=001a1134d90841712504f43d14e5 X-Validation-by: arnaud@spiwack.net Subject: Re: [Caml-list] Batteries Included syntax extensions? --001a1134d90841712504f43d14e5 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable List comprehension in a few (non-syntax checked) lines. TL;DR: list comprehension =3D monadic combinators. let return a =3D [a] let (>>=3D) x f =3D List.(flatten (map f x)) let (>>) x y =3D x >>=3D fun () -> y let guard b =3D if b then [()] else [] With these combinators [ f (x,y) | x <- l ; y <-r ; x=3Dy+1 ] then translates to l >>=3D fun x -> r >>=3D fun y -> guard (x=3Dy+1) >> return (f x) Less compact, no doubt, but still reasonably practical. On 7 March 2014 23:12, Simon Cruanes wrote: > Le Fri, 07 Mar 2014, Yotam Barnoy a =C3=A9crit : > > > I have a question about Batteries Included. Specifically, how do I get > the > > syntax extensions working and which syntax extensions are available? The > > various bits of documentation I've found seemed either contradictory or > did > > not mention any syntax extensions at all. I'm specifically interested in > > things like automatic rope generation and list comprehensions. > > Hi! > > The current version of Batteries is 2.2.0 and its documentation is here: > http://ocaml-batteries-team.github.io/batteries-included/hdoc2/ . As far > as I know, there are no more syntax extensions in Batteries since 2.0.0 > (which explains why it doesn't depend on camlp4). I don't know much > about the "rope generation" you talk about, but list comprehensions are > nicely replaced (imho) by the |> operator: > > List.range 1 `To 10 > |> List.filter (< 5) > |> List.map string_of_int > > You can ask more questions on the Batteries mailing list > ( https://lists.forge.ocamlcore.org/cgi-bin/listinfo/batteries-devel ). > Hope you will find it helpful! > > Cheers, > > -- > Simon > > http://weusepgp.info/ > key 49AA62B6 > fingerprint 949F EB87 8F06 59C6 D7D3 7D8D 4AC0 1D08 49AA 62B6 > --001a1134d90841712504f43d14e5 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
List comprehension in a few (non-syntax checked) line= s. TL;DR: list comprehension =3D monadic combinators.

let return a =3D [a]
let (>>=3D) x f =3D List.(f= latten (map f x))
let (>>) x y =3D x >>=3D fun () -> y
let guard b =3D if b= then [()] else []

With these combinators

[ f (x,y) | x <- l ; y <-r ; x=3Dy+1 ]
then translates to

l >>=3D fun x ->
r >>= =3D fun y ->
guard (x=3Dy+1) >>
return (f x)

Less compact, no doubt, but still reasonably practical.


On 7 March 2014 23:12, Simon Cruanes <simon.cruanes.2007@m4x.org> wrote:
Le Fri, 07 Mar 2014, Yotam Barnoy a =C3=A9crit :

> I have a question about Batteries Included. Specifically, how do I get= the
> syntax extensions working and which syntax extensions are available? T= he
> various bits of documentation I've found seemed either contradicto= ry or did
> not mention any syntax extensions at all. I'm specifically interes= ted in
> things like automatic rope generation and list comprehensions.

Hi!

The current version of Batteries is 2.2.0 and its documentation is here:
http://ocaml-batteries-team.github.io/batteries-included= /hdoc2/ . As far
as I know, there are no more syntax extensions in Batteries since 2.0.0
(which explains why it doesn't depend on camlp4). I don't know much=
about the "rope generation" you talk about, but list comprehensio= ns are
nicely replaced (imho) by the |> operator:

List.range 1 `To 10
=C2=A0 =C2=A0 |> List.filter (< 5)
=C2=A0 =C2=A0 |> List.map string_of_int

You can ask more questions on the Batteries mailing list
( https://lists.forge.ocamlcore.org/cgi-bin/listinfo/= batteries-devel ).
Hope you will find it helpful!

Cheers,

--
Simon

http://weusepgp.info/
key 49AA62B6
fingerprint 949F EB87 8F06 59C6 D7D3 =C2=A07D8D 4AC0 1D08 49AA 62B6

--001a1134d90841712504f43d14e5--