我跟隨Real World OCaml開始使用該語言,並且在某一時刻,我將在模塊簽名中使用s表達式。這是我的mli
文件:無法使用s表達式
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擴展機制,我相信jane street有所有必需的發佈作爲ppx版本。這不是解釋因爲它是一種新的語言功能。我不知道該怎麼去做,但我猜是Google是你的朋友。 – user3240588
顯示你如何編譯它,你使用了什麼命令? –
如果您想了解更多信息,請參閱第10章:*一流的模塊*。 mli被稱爲'Query_Handler.mli'和'ml','Query_Handler.ml'。我使用'corebuild Query_Handler.native'編譯它。另外,我使用ArchLinux並安裝了'camlp4'軟件包。 – RichouHunter