Profile

Statistics
| Branch: | Revision:

cool / src / lib / CoolUtils.ml @ 7c4d2eb4

 1 ```module TArray = struct ``` ``` let any f arr = ``` ``` let rec g idx = ``` ``` if idx >= Array.length arr then false ``` ``` else if f arr.(idx) then true ``` ``` else g (idx + 1) ``` ``` in g 0 ``` ``` let all f arr = not (any (fun x -> not (f x)) arr) ``` ``` let elem (x: 'a) (arr: 'a array) = ``` ``` any (fun y -> x == y) arr ``` ``` let included sub sup = all (fun x -> elem x sup) sub ``` ``` let to_string ts arr = "[| " ^ (Array.fold_right (fun i str -> (ts i) ^" "^ str) arr "|]") ``` ``` let uniq arr = ``` ``` let combine n l = ``` ``` match l with ``` ``` | [] -> [n] ``` ``` | m::tail -> if n == m then l else n::l ``` ``` in ``` ``` Array.of_list (Array.fold_right combine arr []) ``` ```end ``` ```module TList = struct ``` ``` let rec zip l1 l2 = match l1 with ``` ``` | h1::t1 -> (match l2 with ``` ``` | h2::t2 -> (h1,h2)::(zip t1 t2) ``` ``` | [] -> []) ``` ``` | [] -> [] ``` ``` let rec powerset l = match l with ``` ``` | [] -> [[]] ``` ``` | h::t -> let pt = powerset t in ``` ``` let oth = List.map (fun x -> h::x) pt in ``` ``` List.append pt oth ``` ``` let prod la lb = List.concat (List.map (fun a -> List.map (fun b -> (a,b)) lb) la) ``` ``` let empty l = match l with ``` ``` | (_::_) -> false ``` ``` | [] -> true ``` ```end ``` ```let agents = ref ([|1;2;3;4;5|]) ``` ```let cl_get_agents () = !agents ``` ```let cl_set_agents arr = ignore ( ``` ``` agents := arr; ``` ``` Array.fast_sort compare !agents; ``` ``` agents := TArray.uniq !agents) ``` ```let intlist_of_string str = List.map int_of_string (Str.split (Str.regexp "[ \t,]+") str) ``` ```let compose f g x = f (g (x)) ``` ```let flip f y x = f x y ``` ```let eval a f = f a ``` ```let id a = a ```