From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 4B4A37F86A for ; Mon, 10 Mar 2014 11:12:14 +0100 (CET) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of ivg@ieee.org) identity=pra; client-ip=209.85.215.44; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="ivg@ieee.org"; x-sender="ivg@ieee.org"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of ivg@ieee.org designates 209.85.215.44 as permitted sender) identity=mailfrom; client-ip=209.85.215.44; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="ivg@ieee.org"; x-sender="ivg@ieee.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-la0-f44.google.com) identity=helo; client-ip=209.85.215.44; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="ivg@ieee.org"; x-sender="postmaster@mail-la0-f44.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao4CAC+PHVPRVdcslWdsb2JhbABag0GDXagelhciehYOAQEBAQcNCQkSKoIlAQEBAwEBAQEgBEcLBQsJAg4KKgICJwEMAQUBHAYTh3EIBAEIkh2QCYwOoQoXjXM1LwQHgm81gRQEiUuMI4JXgTKFGolzQYRf X-IPAS-Result: Ao4CAC+PHVPRVdcslWdsb2JhbABag0GDXagelhciehYOAQEBAQcNCQkSKoIlAQEBAwEBAQEgBEcLBQsJAg4KKgICJwEMAQUBHAYTh3EIBAEIkh2QCYwOoQoXjXM1LwQHgm81gRQEiUuMI4JXgTKFGolzQYRf X-IronPort-AV: E=Sophos;i="4.97,622,1389740400"; d="scan'208,217";a="51972893" Received: from mail-la0-f44.google.com ([209.85.215.44]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 10 Mar 2014 11:12:13 +0100 Received: by mail-la0-f44.google.com with SMTP id hr13so4546043lab.3 for ; Mon, 10 Mar 2014 03:12:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:references:in-reply-to:mime-version :content-transfer-encoding:content-type:message-id:cc:from:subject :date:to; bh=B6YvjZlEHiqfRT/TrdBMTdskMfmdzv2HKgUWZGle+0w=; b=WiteVdUGhe3pWK33sPP/wgJVaj2lq+DF5gaCjanL8DL7UmGcpymERGvo/oYY63klXS zvtqWuUwSOwCFb8TSJNBYxutjo6vLXT4KuUCZ36T84ancuwZQzZcTv/Pfq4Ntf8nxIf5 QdFZMLmsxCGOx/NkmnzV6VbLp8HwRK8hyACDVH2CB+OySN60+QsqtjBqJl4eBxVqH69q 2T+Yb6tBpc7+ivnL/io8ov44jq9vrrh9101/GDB9EnAAc+LcA7ZJUB8poAsYVmhAWrq7 arjB/zIQ7JJivT42xFhSYVPXY+uN3K+caHNIyQ0FzdJBlG0c9pe6NviviDVFPgR1K8on pkRg== X-Gm-Message-State: ALoCoQksoomOSCj+ET8qyWjJa0MJsoy7RsQmN1yabBYj0HANBBs3CJ6SUmCRIIO93NAgX2SupTkJ X-Received: by 10.112.142.40 with SMTP id rt8mr35182lbb.52.1394446332515; Mon, 10 Mar 2014 03:12:12 -0700 (PDT) Received: from [192.168.0.200] ([213.87.131.107]) by mx.google.com with ESMTPSA id vv8sm5622834lbb.13.2014.03.10.03.12.10 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 10 Mar 2014 03:12:11 -0700 (PDT) References: <20140307221234.GA14634@lenat> In-Reply-To: Mime-Version: 1.0 (1.0) Content-Transfer-Encoding: 7bit Content-Type: multipart/alternative; boundary=Apple-Mail-6791D93D-1BD5-4147-83E7-6B931223BBAF Message-Id: <62822885-676F-4397-9619-A2C390056153@ieee.org> Cc: Simon Cruanes , Yotam Barnoy , Ocaml Mailing List X-Mailer: iPad Mail (11B651) From: Ivan Gotovchits Date: Mon, 10 Mar 2014 14:12:07 +0400 To: Arnaud Spiwack Subject: Re: [Caml-list] Batteries Included syntax extensions? --Apple-Mail-6791D93D-1BD5-4147-83E7-6B931223BBAF Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable By the way, list comprehension is already included in standard ocaml distri= bution. It is not as mighty as batteries one, and slightly differs in synta= x: [ x / 2 | x <- [ 2;4;6] ] > On 10 =D0=BC=D0=B0=D1=80=D1=82=D0=B0 2014 =D0=B3., at 13:17, Arnaud Spiwa= ck wrote: >=20 > List comprehension in a few (non-syntax checked) lines. TL;DR: list compr= ehension =3D monadic combinators. >=20 > 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 [] >=20 > With these combinators >=20 > [ f (x,y) | x <- l ; y <-r ; x=3Dy+1 ] >=20 > then translates to >=20 > l >>=3D fun x -> > r >>=3D fun y -> > guard (x=3Dy+1) >> > return (f x) >=20 > Less compact, no doubt, but still reasonably practical. >=20 >=20 >> On 7 March 2014 23:12, Simon Cruanes wrote: >> Le Fri, 07 Mar 2014, Yotam Barnoy a =C3=A9crit : >>=20 >> > 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 contradictory o= r did >> > not mention any syntax extensions at all. I'm specifically interested = in >> > things like automatic rope generation and list comprehensions. >>=20 >> Hi! >>=20 >> 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: >>=20 >> List.range 1 `To 10 >> |> List.filter (< 5) >> |> List.map string_of_int >>=20 >> 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! >>=20 >> Cheers, >>=20 >> -- >> Simon >>=20 >> http://weusepgp.info/ >> key 49AA62B6 >> fingerprint 949F EB87 8F06 59C6 D7D3 7D8D 4AC0 1D08 49AA 62B6 >=20 --Apple-Mail-6791D93D-1BD5-4147-83E7-6B931223BBAF Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
By the way, list comprehension is = already included in standard ocaml distribution. It is not as mighty as bat= teries one, and slightly differs in syntax:

[ x / = 2 | x <- [ 2;4;6] ]

On 10 =D0=BC=D0=B0=D1=80=D1=82=D0=B0 2= 014 =D0=B3., at 13:17, Arnaud Spiwack <aspiwack@lix.polytechnique.fr> wrote:

<= blockquote type=3D"cite">
List comprehension in a= few (non-syntax checked) lines. TL;DR: list comprehension =3D monadic comb= inators.

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 <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 contradictory o= r 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

= --Apple-Mail-6791D93D-1BD5-4147-83E7-6B931223BBAF--