在 OCaml 中使用 "with fields" 的语法错误
Syntax error using "with fields" in OCaml
我正在使用 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;;
对我来说,我需要在 utop 中添加:
#require "ppx_fields_conv";;
我正在使用 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;;
对我来说,我需要在 utop 中添加:
#require "ppx_fields_conv";;