-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.ml
32 lines (27 loc) · 971 Bytes
/
utils.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
let rec mk_list f t = if (f = t) then [] else f::(mk_list (f+1) t)
let rec zipWith f l1 l2 = match (l1,l2) with
([],[]) -> []
| ([],a) -> a
| (a,[]) -> a
| (x::xs,y::ys) -> (f x y) :: (zipWith f xs ys)
let orl = zipWith (fun x y -> x||y)
let rec iterate f times a = if times = 0 then f(a) else f(iterate f (times - 1) a);;
let compose f g = function x -> f(g(x))
let (%) = compose
let soi i = string_of_int i
(* buggy version... *)
let rec zipWith2 f l1 l2 = match (l1,l2) with
([],[]) -> []
| _ -> (f (List.hd l1) (List.hd l2))::zipWith2 f (List.tl l1) (List.tl l2);;
(* hashtable to list *)
let h2l h = Hashtbl.fold (fun k v acc -> (k, v) :: acc) h []
let lxy2yx l = List.map (fun (x,y) -> (y,x)) l
let save_struct s fn =
let o = BatPervasives.open_out fn in
BatPervasives.output_value o s;
BatPervasives.close_out o
let load_struct fn =
let i = BatPervasives.open_in fn in
let v = BatPervasives.input_value i in
BatPervasives.close_in i;
v