简体   繁体   English

在OCaml中使用Z3模块时出错

[英]Error while using Z3 module in OCaml

I am new to OCaml. 我是OCaml的新手。 I installed Z3 module as mentioned in this link 我安装了此链接中提到的Z3模块

I am calling Z3 using the command: 我正在使用以下命令调用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

where $1 is replaced with file name. 其中$ 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)

In the above code I am defining some types. 在上面的代码中,我定义了一些类型。 Now if I include the command "open Z3", I am getting "Error: Unbound module Set.Make". 现在,如果我包含命令“ open Z3”,则会收到“错误:未绑定模块Set.Make”。

I could run test code which uses Z3 module with out any difficulty, but unable to run with the above code. 我可以毫无困难地运行使用Z3模块的测试代码,但是无法使用上述代码运行。

The error message in this case is a little bit confusing. 在这种情况下,错误消息有些混乱。 The problem is that Z3 also provides a module called Set , which doesn't have a make function. 问题在于Z3还提供了一个名为Set的模块,该模块没有make函数。 This can be overcome simply by not importing everything from Z3, as there are a number of modulse that might clash with others. 可以通过不从Z3导入所有内容来简单地解决此问题,因为存在许多可能与其他模块冲突的模块。 For example, 例如,

open Z3.Expr
open Z3.Boolean

will work fine and opens only the Z3.Expr and Z3.Boolean modules, but not the Z3.Set module. 将正常工作,并且仅打开Z3.ExprZ3.Boolean模块,而不打开Z3.Set模块。 so that we can write an example function: 这样我们就可以编写一个示例函数:

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

If Z3.Boolean is not opened, we would have to write Z3.Boolean.mk_and instead, and similarly we can still access Z3's Set module functions by prefixing them with Z3.Set. 如果未打开Z3.Boolean ,则必须编写Z3.Boolean.mk_and ,并且类似地,我们仍然可以通过为Z3的Set模块函数添加前缀Z3.Boolean.mk_and来访问它们Z3.Set.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM