summaryrefslogtreecommitdiff
path: root/libs/util.ml
blob: 522c3ec82ed8b2e964e3b651c8a232612e01aef4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
exception TypeError

module VarMap = Mapext.Make(String)
exception Duplicate of string
let disjoint_union k a b = match a, b with
  | Some x, None -> Some x
  | None, Some y -> Some y 
  | _ -> raise (Duplicate k)

let rec fix equal f s =
  let fs = f s in
  if equal fs s
    then fs
    else fix equal f fs

let (@@) f x = f x

let print_list x l =
  Format.printf "%s: " x;
  let rec aux = function
    | [] -> ()
    | [a] -> Format.printf "%s" a
    | p::q -> Format.printf "%s, " p; aux q
  in
  Format.printf "["; aux l; Format.printf "]@."

let uid =
  let c = ref 0 in
  fun () -> c := !c + 1; string_of_int !c