Generate OCaml code that uses list comprehension

From this SO: List Comprehension question in Ocaml? , I could install the understanding package using opam install pa_comprehension and use the package in the REPL add-on.

 # #require "pa_comprehension";; # open Batteries;; # [? 2 * x | x <- 0 -- max_int ; x * x > 3 ?];; - : int Batteries.Enum.t = <abstr> 

Then, how can I compile the code?

+1
source share
1 answer

Unfortunately, since the pa_comprehension package name does not end with the .syntax extension, this is a little more complicated than it should be. (The fact that this question is still not fixed shows that using pa_comprehension not very popular in modern OCaml). Thus, without proper expansion, we need to do everything manually. If your file is named pr.ml , then the correct call is:

 $ ocamlbuild -use-ocamlfind -syntax camlp4o -pkg camlp4,pa_comprehension pr.native 

If you do not want to enter it each time, you can create a _tags file with the following contents:

 $ cat _tags <**/*> : package(camlp4),syntax(camlp4o),package(pa_comprehension) 

In this case, the command line spell is a little simpler:

 $ ocamlbuild -use-ocamlfind pr.native 
+4
source

Source: https://habr.com/ru/post/1214294/


All Articles