* [Caml-list] Batteries Included syntax extensions? @ 2014-03-07 18:04 Yotam Barnoy 2014-03-07 22:12 ` Simon Cruanes 0 siblings, 1 reply; 6+ messages in thread From: Yotam Barnoy @ 2014-03-07 18:04 UTC (permalink / raw) To: Ocaml Mailing List [-- Attachment #1: Type: text/plain, Size: 422 bytes --] 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. I have the latest version installed from opam. Thanks Yotam [-- Attachment #2: Type: text/html, Size: 497 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Batteries Included syntax extensions? 2014-03-07 18:04 [Caml-list] Batteries Included syntax extensions? Yotam Barnoy @ 2014-03-07 22:12 ` Simon Cruanes 2014-03-10 9:17 ` Arnaud Spiwack 0 siblings, 1 reply; 6+ messages in thread From: Simon Cruanes @ 2014-03-07 22:12 UTC (permalink / raw) To: Yotam Barnoy; +Cc: Ocaml Mailing List [-- Attachment #1: Type: text/plain, Size: 1212 bytes --] 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: application/pgp-signature, Size: 836 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Batteries Included syntax extensions? 2014-03-07 22:12 ` Simon Cruanes @ 2014-03-10 9:17 ` Arnaud Spiwack 2014-03-10 10:12 ` Ivan Gotovchits 0 siblings, 1 reply; 6+ messages in thread From: Arnaud Spiwack @ 2014-03-10 9:17 UTC (permalink / raw) To: Simon Cruanes; +Cc: Yotam Barnoy, Ocaml Mailing List [-- 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 --] ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Batteries Included syntax extensions? 2014-03-10 9:17 ` Arnaud Spiwack @ 2014-03-10 10:12 ` Ivan Gotovchits 2014-03-10 10:19 ` ygrek 0 siblings, 1 reply; 6+ messages in thread From: Ivan Gotovchits @ 2014-03-10 10:12 UTC (permalink / raw) To: Arnaud Spiwack; +Cc: Simon Cruanes, Yotam Barnoy, Ocaml Mailing List [-- Attachment #1: Type: text/plain, Size: 2175 bytes --] By the way, list comprehension is already included in standard ocaml distribution. It is not as mighty as batteries one, and slightly differs in syntax: [ x / 2 | x <- [ 2;4;6] ] > On 10 марта 2014 г., at 13:17, Arnaud Spiwack <aspiwack@lix.polytechnique.fr> wrote: > > 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: 3327 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Batteries Included syntax extensions? 2014-03-10 10:12 ` Ivan Gotovchits @ 2014-03-10 10:19 ` ygrek 2014-03-10 10:43 ` ygrek 0 siblings, 1 reply; 6+ messages in thread From: ygrek @ 2014-03-10 10:19 UTC (permalink / raw) To: Ocaml Mailing List On Mon, 10 Mar 2014 14:12:07 +0400 Ivan Gotovchits <ivg@ieee.org> wrote: > By the way, list comprehension is already included in standard ocaml distribution. It is not as mighty as batteries one, and slightly differs in syntax: > > [ x / 2 | x <- [ 2;4;6] ] Wut? Can you elaborate on this? $ ocaml -init - OCaml version 4.01.0 # [ x / 2 | x <- [ 2;4;6] ];; Characters 8-9: [ x / 2 | x <- [ 2;4;6] ];; ^ Error: Syntax error -- ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Batteries Included syntax extensions? 2014-03-10 10:19 ` ygrek @ 2014-03-10 10:43 ` ygrek 0 siblings, 0 replies; 6+ messages in thread From: ygrek @ 2014-03-10 10:43 UTC (permalink / raw) To: caml-list On Mon, 10 Mar 2014 18:19:36 +0800 ygrek <ygrek@autistici.org> wrote: > Can you elaborate on this? Answering my own question.. :) $ ocaml OCaml version 4.00.1 .ocamlinit done # #camlp4o;; Camlp4 Parsing version 4.00.1 # #require "camlp4.listcomprehension";; # [ x / 2 | x <- [ 2;4;6] ];; - : int list = [1; 2; 3] -- ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-03-10 10:44 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2014-03-07 18:04 [Caml-list] Batteries Included syntax extensions? Yotam Barnoy 2014-03-07 22:12 ` Simon Cruanes 2014-03-10 9:17 ` Arnaud Spiwack 2014-03-10 10:12 ` Ivan Gotovchits 2014-03-10 10:19 ` ygrek 2014-03-10 10:43 ` ygrek
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox