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?
Unfortunately, since
pa_comprehensionpackage name is not ended with.syntaxextension, this is a little bit harder than it should be. (The fact that this issue is still not fixed, shows that usingpa_comprehensionis not very popular in modern OCaml). So, without the proper extension, we need to do everything manually. If your file is namedpr.ml, then the correct invocation is:If you don't wan't to type it every time, then you can create
_tagsfile, with the following contents:In that case, the command line spell is a little bit easier: