var.ml 968 Bytes
 Pietro Abate committed Jan 15, 2014 1 2 3 4 5 `````` type t = String.t type var = [ `Var of t ] type 'a pairvar = [ `Atm of 'a | var ] `````` Pietro Abate committed Jan 22, 2014 6 ``````let compare (x : var) (y : var) = Pervasives.compare x y `````` Pietro Abate committed Jan 30, 2014 7 ``````let equal x y = Pervasives.compare x y = 0 `````` Pietro Abate committed Jan 22, 2014 8 9 ``````let hash (v : var) = Hashtbl.hash v `````` Pietro Abate committed Jan 15, 2014 10 11 ``````module Make (X : Custom.T) = struct type t = X.t pairvar `````` Pietro Abate committed Jan 22, 2014 12 `````` let hash = function `Atm t -> X.hash t | `Var s -> hash (`Var s) `````` Pietro Abate committed Jan 15, 2014 13 14 15 `````` let check = function `Atm t -> X.check t | `Var _ -> () let compare t1 t2 = match t1,t2 with `````` Pietro Abate committed Jan 22, 2014 16 `````` |`Var x, `Var y -> compare (`Var x) (`Var y) `````` Pietro Abate committed Jan 15, 2014 17 18 19 20 21 `````` |`Atm x, `Atm y -> X.compare x y |`Var _, `Atm _ -> -1 |`Atm _, `Var _ -> 1 let equal t1 t2 = (compare t1 t2) = 0 `````` Pietro Abate committed Jan 22, 2014 22 `````` `````` Pietro Abate committed Jan 15, 2014 23 24 25 26 27 28 29 30 31 32 33 `````` let dump ppf = function |`Atm x -> X.dump ppf x |`Var x -> Format.fprintf ppf "`\$%s" x end let fresh : unit -> var = let counter = ref 0 in fun _ -> let v = `Var (Printf.sprintf "_fresh_%d" !counter) in incr counter; v `````` Pietro Abate committed Jan 20, 2014 34 35 36 37 38 39 `````` module Set = Set.Make( struct type t = var let compare = Pervasives.compare end)``````