在OCaml中使用Z3模块时出错

在OCaml中使用Z3模块时出错,ocaml,z3,Ocaml,Z3,我是OCaml的新手。我安装了本节中提到的Z3模块 我正在使用以下命令调用Z3: ocamlc -custom -o ml_example.byte -I ~/Downloads/z3-unstable/build/api/ml -cclib "-L ~/Downloads/z3-unstable/build/ -lz3" nums.cma z3ml.cma $1 其中$1替换为文件名 type loc = int type var = string type exp = | Mul

我是OCaml的新手。我安装了本节中提到的Z3模块

我正在使用以下命令调用Z3:

ocamlc -custom -o ml_example.byte -I ~/Downloads/z3-unstable/build/api/ml -cclib "-L ~/Downloads/z3-unstable/build/ -lz3" nums.cma z3ml.cma  $1
其中$1替换为文件名

type loc = int

type var = string

type exp =
 | Mul of int * exp
 | Add of exp * exp
 | Sub of exp * exp
 | Const of int
 | Var of var

 type formula =
  | Eq of exp * exp
  | Geq of exp
  | Gt  of exp

 type stmt =
  | Assign  of var * exp
  | Assume  of formula

  type transition = loc * stmt * loc

module OrdVar =
struct
  type t = var
  let compare = Pervasives.compare
end
module VarSets = Set.Make( OrdVar )

type vars = VarSets.t

module OrdTrans =
struct
  type t = transition
  let compare = Pervasives.compare
end
module TransitionSets = Set.Make( OrdTrans )

type transitionSet = TransitionSets.t

type program = vars * loc * transitionSet * loc

let ex1 () : program = 
    let vset = VarSets.empty in
    let vset = VarSets.add "x" vset in
    let vset = VarSets.add "y" vset in
    let vset = VarSets.add "z" vset in
    let ts = TransitionSets.empty in
    (* 0  X' = X + 1 *)
    let stmt1 = Assign( "x", Add( Var("x"), Const(1) ) ) in
    let tr1 = (0,stmt1,1) in
    let ts = TransitionSets.add tr1 ts in
    (vset,0,ts,10)
在上面的代码中,我定义了一些类型。现在,如果我包含命令“openz3”,我将得到“Error:unboundmoduleset.Make”


我可以毫无困难地运行使用Z3模块的测试代码,但无法使用上述代码运行

本例中的错误消息有点混乱。问题是Z3还提供了一个名为
Set
的模块,它没有
make
功能。这可以通过不从Z3导入所有内容来克服,因为有许多模块可能与其他模块冲突。比如说,

open Z3.Expr
open Z3.Boolean
将正常工作,只打开
Z3.Expr
Z3.Boolean
模块,但不打开
Z3.Set
模块。因此,我们可以编写一个示例函数:

let myfun (ctx:Z3.context) (args:expr list) = 
  mk_and ctx args

如果未打开
Z3.Boolean
,我们将不得不编写
Z3.Boolean.mk_和
,类似地,我们仍然可以通过在Z3的
Set
模块函数前面加上
Z3.Set.

打开的Z3
放在哪里?你真的能提供不编译的代码吗?我试着把“openz3”放在代码的顶部,也放在我上面发布的代码的末尾。我甚至没有开始使用z3命令,但仍然得到语法错误,这是没有意义的。如果您得到的是
未绑定的模块Z3
,这是可以理解的,但是没有对您的文件进行预处理,可能会生成语法错误的代码。@ChriS对问题中的错误表示抱歉。当我包含z3库时,它说的是“Error:unboundmoduleset.Make”。