Phani Raj
Phani Raj

Reputation: 173

Error while using Z3 module in OCaml

I am new to OCaml. I installed Z3 module as mentioned in this link

I am calling Z3 using the command:

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.

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".

I could run test code which uses Z3 module with out any difficulty, but unable to run with the above code.

Upvotes: 1

Views: 479

Answers (1)

Christoph Wintersteiger
Christoph Wintersteiger

Reputation: 8393

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. This can be overcome simply by not importing everything from Z3, as there are a number of modulse that might clash with others. 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. 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.

Upvotes: 2

Related Questions