代码之家  ›  专栏  ›  技术社区  ›  nicolas

如何强制ppx使用ocaml版本?

  •  0
  • nicolas  · 技术社区  · 4 年前

    我有下面的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
    

    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公司 使用4.13,还是在ppx与给定版本不兼容时收到警告?(还是一个bug?)

    0 回复  |  直到 4 年前
        1
  •  2
  •   ivg    4 年前

    可执行文件或库只能由同一编译器编译的编译单元组成。换句话说,您不能用一个编译器构建项目的某些部分,而用另一个编译器来构建其他部分。

    使用dune编译OCaml项目时,将在PATH变量(在Linux中)中指定的目录中搜索编译器。您可以使用shell命令查看选择了哪个编译器 which ocaml ocaml -version 会告诉你它的版本。

    opam switch create 4.13.1
    

    eval $(opam env)
    

    这将确保新安装的OCaml版本在您的路径中可用。再次检查是否使用 .

    最后,使用安装项目所需的依赖项 opam install

    推荐文章