From: Arnaud Spiwack <aspiwack@lix.polytechnique.fr>
To: Simon Cruanes <simon.cruanes.2007@m4x.org>
Cc: Yotam Barnoy <yotambarnoy@gmail.com>,
Ocaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Batteries Included syntax extensions?
Date: Mon, 10 Mar 2014 10:17:16 +0100 [thread overview]
Message-ID: <CAMoPVjfiBkCtsa84dBVW7EzcJ9G=siojUDM1LJiMxQ__Ju+8YA@mail.gmail.com> (raw)
In-Reply-To: <20140307221234.GA14634@lenat>
[-- Attachment #1: Type: text/plain, Size: 1814 bytes --]
List comprehension in a few (non-syntax checked) lines. TL;DR: list
comprehension = monadic combinators.
let return a = [a]
let (>>=) x f = List.(flatten (map f x))
let (>>) x y = x >>= fun () -> y
let guard b = if b then [()] else []
With these combinators
[ f (x,y) | x <- l ; y <-r ; x=y+1 ]
then translates to
l >>= fun x ->
r >>= fun y ->
guard (x=y+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 écrit :
>
> > 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
>
[-- Attachment #2: Type: text/html, Size: 2781 bytes --]
next prev parent reply other threads:[~2014-03-10 9:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-07 18:04 Yotam Barnoy
2014-03-07 22:12 ` Simon Cruanes
2014-03-10 9:17 ` Arnaud Spiwack [this message]
2014-03-10 10:12 ` Ivan Gotovchits
2014-03-10 10:19 ` ygrek
2014-03-10 10:43 ` ygrek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAMoPVjfiBkCtsa84dBVW7EzcJ9G=siojUDM1LJiMxQ__Ju+8YA@mail.gmail.com' \
--to=aspiwack@lix.polytechnique.fr \
--cc=caml-list@inria.fr \
--cc=simon.cruanes.2007@m4x.org \
--cc=yotambarnoy@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox