Building OCaml code that uses list comprehension

大城市里の小女人 提交于 2019-12-11 12:17:03

问题


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?


回答1:


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

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


来源:https://stackoverflow.com/questions/28751359/building-ocaml-code-that-uses-list-comprehension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!