forked from Kappa-Dev/ExtentionBases
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.ml
49 lines (39 loc) · 1.64 KB
/
lib.ml
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
module type OrderedType = sig type t val compare : t -> t -> int val to_string : t -> string end
module IntMap = Map.Make (struct type t = int let compare = compare end)
module IntSet = Set.Make (struct type t = int let compare = compare end)
module StringMap = Map.Make (struct type t = string let compare = compare end)
module Dict =
struct
type t = {int_of_str : int StringMap.t ; str_of_int : string IntMap.t ; fresh : int}
let empty = {int_of_str = StringMap.empty ; str_of_int = IntMap.empty ; fresh = 0}
let to_id x d = StringMap.find x d.int_of_str
let to_name x d = IntMap.find x d.str_of_int
let add i n d = {d with str_of_int = IntMap.add i n d.str_of_int ; int_of_str = StringMap.add n i d.int_of_str}
let fresh d = (d.fresh, {d with fresh = d.fresh+1})
end
module Util =
struct
let db_mode = ref false
let db () = !db_mode
let flush_string = fun x -> print_string x ; flush stdout
let debug_mode () =
(print_string "Entering debug mode\n" ; db_mode := true)
let proj_left = (fun (x,_) -> x)
let proj_right = (fun (_,y) -> y)
let ask_until str f =
let inp = ref "" in
let init = ref true in
while (proj_left (f !inp)) && !init do
print_string !inp ; flush stdout ;
init := false ;
print_string str ; flush stdout ;
inp := Pervasives.input_line stdin ;
done ;
proj_right (f !inp)
let red str = "\027[91m"^str^"\027[0m"
let green str = "\027[92m"^str^"\027[0m"
let yellow str = "\027[93m"^str^"\027[0m"
let blue str = "\027[94m"^str^"\027[0m"
let to_list fold x =
fold (fun i cont -> i::cont) x []
end