在Hashtbl上编译OCaml Book示例

时间:2015-05-10 20:41:03

标签: ocaml

我试图编译以下示例

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 声明的错误。我哪里错了?

1 个答案:

答案 0 :(得分:4)

核心库附带了一个简化生活的工具。它名为corebuild。有了它,您只需编译:

corebuild algebra.native

它将生成名为algrebra.native

的可执行文件

关于您的尝试,您指的是core.cmxaocamlopt不知道在哪里可以找到它。此外,您需要使用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;

相关问题