(* Just some random utility functions *) exception Error of string let rec join str = function | [] -> "" | a::[] -> a | a::b::t -> join str ((a ^ str ^ b)::t) let rec join_end str = function | [] -> "" | a::t -> a ^ str ^ (join_end str t) let bonus_newline s = if s = "" then s else s ^ "\n" let rec indent n = match n with 0 -> "" | i -> " " ^ (indent (i - 1));; (* Split a list into two parts; the length of the first part is given. *) let split_at_n l n = let rec split_2 l i f = match l with [] -> (f,[]) | h::t -> if (i=0) then (f,h::t) else ( split_2 t (i-1) (f@[h]) ) in split_2 l n [] let rec list_contains e = function | [] -> false | h::t -> if h = e then true else list_contains e t let hash_keys_to_list hash = (* BatHashtbl.keys returns a BatEnum, let's turn it into a plain list *) BatEnum.fold (fun b a -> a::b) [] (BatHashtbl.keys hash) let hash_to_pairs_list hash = BatEnum.fold (fun b a -> a::b) [] (BatHashtbl.enum hash)