我有下面的OCaml文件,它在没有ppx的情况下正确编译,并在这个dune文件中失败
(library
(name so_proj)
(preprocess
(pps
ppx_inline_test
ppx_deriving.show
ppx_deriving.ord
ppx_deriving.map
ppx_deriving.eq
ppx_deriving.fold
ppx_deriving.iter)))并与之合作
(library
(name so_proj))错误是
File "SO_naming_existential.ml", line 23, characters 16-18:
23 | fun (Mod (type xr) (m : xr)) ->
^^
Error: migration error: existentials in pattern-matching is not supported before OCaml 4.13下面是有问题的OCaml文件,它使用了一个新的语法(当它不可用时提供了一个等价的--我相信--版本)
type existentiel = Mod : 'x -> existentiel
module type existentiel_m = sig
type x
val value : x
end
let to_Module : existentiel -> (module existentiel_m) =
fun (Mod m) ->
let namedxr : type xr. xr -> (module existentiel_m) =
fun v ->
(module struct
type x = xr
let value = v
end)
in
namedxr m
(* Since 4.13 https://github.com/ocaml/ocaml/pull/9584 *)
let to_Module2 : existentiel -> (module existentiel_m) =
fun (Mod (type xr) (m : xr)) ->
(module struct
type x = xr
let value = m
end)确认错误的来源(并先运行以避免浪费时间.)命令dune build --verbose确实指向在ppx中发生的错误
Running[2]: (cd _build/default && .ppx/0789030747a4993265eb655c993f5cab/ppx.exe --cookie 'inline_tests="enabled"' --cookie 'library-name="so_proj"' -o SO_naming_existential.pp.ml --impl SO_naming_existential.ml -corrected-suffix .ppx-corrected -diff-cmd - -dump-ast)
Command [2] exited with code 1:
$ (cd _build/default && .ppx/0789030747a4993265eb655c993f5cab/ppx.exe --cookie 'inline_tests="enabled"' --cookie 'library-name="so_proj"' -o SO_naming_existential.pp.ml --impl SO_naming_existential.ml -corrected-suffix .ppx-corrected -diff-cmd - -dump-ast)
File "SO_naming_existential.ml", line 23, characters 16-18:
23 | fun (Mod (type xr) (m : xr)) ->
^^
Error: migration error: existentials in pattern-matching is not supported before OCaml 4.13当一个ppx与给定版本不兼容时,可以强制ppx使用4.13,或者得到警告吗?(或者说是个窃听器?)
发布于 2022-02-01 00:39:25
可执行文件或库只能由由同一编译器编译的编译单元组成。换句话说,您不能用一个编译器构建项目的某些部分,而不能用另一个编译器构建其他部分。
当您使用沙丘编译OCaml项目时,编译器将在PATH变量中指定的目录中搜索(在Linux中)。您可以看到使用which ocaml命令选择了哪个编译器。ocaml -version会告诉你它的版本。
如果您正在使用opam (很可能是这样),则可以使用以下shell命令安装所需的编译器版本,
opam switch create 4.13.1完成后,用
eval $(opam env)这将确保新安装的OCaml版本在您的path中可用。使用which ocaml和ocaml -version进行二次检查。
最后,使用opam install安装项目所需的依赖项,并重新构建项目。
https://stackoverflow.com/questions/70904007
复制相似问题