Ocaml 无法使用s表达式

Ocaml 无法使用s表达式,ocaml,s-expression,Ocaml,S Expression,我将开始学习该语言,并且,在某一点上,我将在模块签名中使用s表达式。这是我的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

我将开始学习该语言,并且,在某一点上,我将在模块签名中使用s表达式。这是我的
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.
Error: Parse Error: "end" expected after [sig_items] (in [module type])
因此,我打开了
utop
,尝试在一个更简单的示例中使用sexp

module type Test = sig
  type t with sexp
end;;
但我得到了以下错误:

File "Query_Handler.mli", line 4, characters 12-16:
Error: Syntax error
Command exited with code 2.
Error: Parse Error: "end" expected after [sig_items] (in [module type])
然而,
sexplib
已经安装,书中和我在互联网上的搜索都没有提到使用这种语法的任何“先决条件”


我觉得我错过了什么。有什么想法吗(

这是因为sexp库已被重写以使用

opencore.Std
模块类型查询_handler=sig
(**查询处理程序的配置。请注意,这可以是
转换为s表达式*)或从s表达式*)
类型配置[]派生sexp]
(**查询处理服务的名称*)
val名称:string
(**查询处理程序的状态*)
t型
(**从配置创建新的查询处理程序*)
val创建:配置->t
(**评估给定查询,其中输入和输出都是
s-表达式*)
val eval:t->Sexp.t->Sexp.t或_error.t
结束
模块Unique=struct
类型config=int[@@dering sexp]
类型t={mutable next_id:int}
让name=“唯一”
让我们创建start_at={next_id=start_at}
让我们来评估一下=
匹配或出错。请尝试使用(fun()->unit of_sexp sexp)和
|错误uu作为错误->错误
|好的()->
让response=Ok(Int.sexp\u of\u t.next\u id)输入
t、 下一个id 0&&p[0]='/'
让name=“ls”
让我们创建cwd={cwd}
让我们来评估一下=
匹配或出错。请尝试使用(fun()->string\u of_sexp sexp)和
|错误uu作为错误->错误
|Ok目录->
让目录=
如果是abs dir,那么dir
else Filename.concat t.cwd dir
在里面
Ok(字符串的Array.sexp_.sexp_(Sys.readdir))
结束
模块类型Query\u handler\u instance=sig
模块查询处理程序:查询处理程序
val this:Query_handler.t
结束
让生成_实例(类型a)
(模块Q:类型为config=a的查询处理程序)
配置=
(模块结构
模块查询\u处理程序=Q
让这个=Q.createconfig
结束:查询\处理程序\实例)
让我们构建\u分派\u表处理程序=
让table=String.table.create()在
List.iter处理程序
~f:(fun((模块一:查询处理程序\实例)作为实例)->
Hashtbl.replace table~key:I.Query\u handler.name~data:instance);
桌子
让dispatch\u表名和查询=
将名称和查询与匹配
|Sexp.List[Sexp.Atom名称;查询]->
开始匹配Hashtbl.find dispatch_表名
|无->
或_error.error“找不到匹配的处理程序”
name String.sexp\u of\t
|部分(模块I:查询\u处理程序\u实例)->
I.Query\u handler.eval I.此查询
结束
| _ ->
或\u error.error\u字符串“格式错误的查询”
让rec cli分派\u表=
printf“>>>%!”;
让结果=
将输入线stdin与
|“没有——>”停下来
|一些行->
匹配或出错。使用(fun()->Sexp.of_字符串行)尝试
|错误e->`继续(错误.to_字符串_)
|确定查询->
开始使用匹配分派表查询
|错误e->`继续(错误.to_字符串_)
|Ok s->`继续(Sexp.to_string_hum s)
结束;
在里面
匹配结果
|`停止->()
|`Continue msg->
printf“%s\n%”消息;
cli调度表
让unique_instance=build_instance(模块唯一)0
让list\u dir\u instance=build\u instance(模块list\u dir)“/var”
模块加载器=struct
类型配置=(模块查询\u处理程序)列表sexp\u不透明[@@dering sexp]
类型t={known:(模块查询处理程序)String.Table.t
;活动:(模块查询处理程序实例)String.Table.t
}
让name=“loader”
让我们创建已知的列表=
让active=String.Table.create()在
let known=中的String.Table.create()
List.iter已知列表
~f:(fun((模块Q:Query\u handler)作为Q)->
Hashtbl.replace known~ key:Q.name~ data:Q);
{已知;活动}
让我们加载t处理程序的名称配置=
如果Hashtbl.mem t.active handler\u name,则
或_error.error“无法重新注册活动处理程序”
处理程序\u name String.sexp\u of \u t
其他的
将Hashtbl.find t.known handler_名称与匹配
|无->
或\u error.error“未知处理程序”处理程序\u name String.sexp\u of \u t
|一些(模块Q:查询处理程序)->
举个例子=
(模块结构
模块查询\u处理程序=Q
让this=Q.create(Q.config\u of_sexp config)
结束:查询\处理程序\实例)
在里面
Hashtbl.replace t.active~key:handler\u name~data:instance;
好的,六分机
让我们卸载t handler\u名称=
如果不是(Hashtbl.mem t.active handler_name),则
或\u error.error“Handler not active”Handler\u name String.sexp\u of \u t
否则,如果处理程序_name=name,则
或\u error.error\u字符串“卸载自己是不明智的”
否则(
Hashtbl.remove t.activehandler\u name;
好的,六分机
)
类型请求=
|字符串的加载*Sexp.t
|卸载字符串
|已知服务
|主动_服务[@@deriving sexp]
让我们来评估一下=
匹配或出错。尝试使用(fun()->request\u of_sexp sexp)和
|错误uu作为错误->错误
|Ok resp->
匹配
|Load(name,config)->Load t name config
|卸载名称->卸载t名称
|已知_服务->
确定[%sexp((Hashtbl.keys t.known):字符串列表)]
|活动服务->
确定[%sexp((Hashtbl.keys t.active):字符串列表)]
结束

这是我的~/.ocamlinit;只需注释掉camlp4。utop应该可以很好地工作

#use "topfind";;
#warnings "+9"
#thread;;
(*camlp4;;*)
#require "core.top";;
#require "core_extended";;
#require "core_bench";;
#require "ppx_jane";;
#require "ctypes";;
#require "ctypes.foreign";;

with sexp语法依赖于camlp4扩展——这是