【发布时间】:2016-04-27 17:08:00
【问题描述】:
我正在关注 Real World OCaml 以开始使用该语言,并且在某一时刻,我将在模块签名中使用 s-expressions。这是我的mli 文件:
open Core.Std
(** Configuration type for query handlers *)
type config with sexp
(** Name of the query handler *)
val name : string
(** Query handler abstract type *)
type t
(** Create a query handler from an existing [config] *)
val create : config -> t
(** Evaluate a query, where both input and output an s-expressions. *)
val eval : t -> Sexp.t -> Sexp.t Or_error.t
但是,在编译该接口的实现时,我收到以下错误:
File "Query_Handler.mli", line 4, characters 12-16:
Error: Syntax error
Command exited with code 2.
所以我打开utop 来尝试with sexp 一个更简单的例子:
module type Test = sig
type t with sexp
end;;
但我收到以下错误:
Error: Parse Error: "end" expected after [sig_items] (in [module type])
但是,sexplib 已安装,并且本书和我在 Internet 上的搜索均未提及使用此语法的任何“先决条件”。
我觉得我错过了什么。任何的想法? :(
【问题讨论】:
-
with sexp 语法依赖于camlp4 扩展——这应该在使用之前在书中的某个地方进行解释。执行此操作的现代方法是改用 ppx 扩展机制。我相信简街也有所有必要的东西作为 ppx 版本发布。这在书中没有解释,因为它是一个新的语言特性。不过我不知道在哪里查找如何操作——我猜 Google 是你的朋友。
-
显示你是如何编译它的,你使用什么命令?
-
如果您想了解更多信息,请参阅第 10 章:一流模块。 mli 称为
Query_Handler.mli和ml、Query_Handler.ml。我使用corebuild Query_Handler.native编译它。另外,我使用 ArchLinux 并且安装了包camlp4。
标签: ocaml s-expression