ocaml之在 OCaml 中使用 "with fields"的语法错误
emanlee
阅读:72
2025-06-02 22:19:02
评论:0
我在使用 Real World OCaml 时遇到以下代码的语法错误:
`# module Logon = struct
type t =
{ session_id: string;
time: Time.t;
user: string;
credentials: string;
}
with fields
end;;
在运行时,Utop 会在单词“with”下划线并抛出语法错误。我自己尝试过类似的、更简单的例子,但得到了同样的错误。对正在发生的事情有什么想法吗?
编辑:添加了省略的“}”。
请您参考如下方法:
对于 ocaml 4.01.0 : 在 utop 中:#require "fieldslib.syntax";;
正在解决这个问题。 (...不要忘记运行 opam install fieldslib
)。
对于最近的 ocaml : (得到一些提示 here )。
opam install ppx_jane fieldslib
#require "ppx_jane";;
#require "fieldslib";;
module Logon = struct
type t =
{ session_id: string;
time: Time.t;
user: string;
credentials: string;
}
[@@deriving fields]
end;;
声明
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。