构建使用列表理解的OCaml代码 [英] Building OCaml code that uses list comprehension
问题描述
从这个SO问题中:在Ocaml中进行列表理解?,我可以安装理解包opam install pa_comprehension
,并在顶级REPL中使用该软件包.
From this SO question: List Comprehension in Ocaml?, I could install the comprehension package with opam install pa_comprehension
, and use the package in toplevel REPL.
# #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?
推荐答案
不幸的是,由于pa_comprehension
软件包名称不以.syntax
扩展名结尾,因此这比应做的要难一些. (此问题仍未得到解决的事实表明,在现代OCaml中使用pa_comprehension
并不十分流行).因此,如果没有适当的扩展,我们需要手动进行所有操作.如果您的文件名为pr.ml
,则正确的调用是:
Unfortunately, since pa_comprehension
package name is not ended with .syntax
extension, this is a little bit harder than it should be. (The fact that this issue is still not fixed, shows that using pa_comprehension
is not very popular in modern OCaml). So, without the proper extension, we need to do everything manually. If your file is named pr.ml
, then the correct invocation is:
$ ocamlbuild -use-ocamlfind -syntax camlp4o -pkg camlp4,pa_comprehension pr.native
如果不想每次都键入它,则可以创建具有以下内容的_tags
文件:
If you don't wan't to type it every time, then you can create _tags
file, with the following contents:
$ cat _tags
<**/*> : package(camlp4),syntax(camlp4o),package(pa_comprehension)
在这种情况下,命令行拼写要简单一些:
In that case, the command line spell is a little bit easier:
$ ocamlbuild -use-ocamlfind pr.native
这篇关于构建使用列表理解的OCaml代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!