我试图编译以下示例
open Core.Std
module Foo_and_bar : sig
type t = S of string | I of int
include Hashable.S with type t := t
end = struct
module T = struct
type t = S of string | I of int with sexp, compare
let hash t1 t2 = (hashData t1)
end
include T
include Comparable.Make(T)
end;;
camlopt -o exec core.cmxa algebra.ml
可以在此book上找到,但结果是,我收到了 sexp 声明的错误。我哪里错了?
答案 0 :(得分:4)
核心库附带了一个简化生活的工具。它名为corebuild
。有了它,您只需编译:
corebuild algebra.native
它将生成名为algrebra.native
关于您的尝试,您指的是core.cmxa
而ocamlopt
不知道在哪里可以找到它。此外,您需要使用camlp4
预处理器来启用语法扩展。使用ocamlfind
包裹ocamlopt
这可以很容易地实现:
ocamlfind ocamlopt -thread -syntax camlp4o -package core.syntax algebra.ml -o exec
此处,-syntax camlp4o
启用语法扩展,-package core.syntax
启用核心,并且还启用Core的语法扩展。
但我仍然建议使用corebuild
,至少在开始时使用address = address | 0;
。