Project

General

Profile

Revision 14d694c7 src/utils.ml

View differences:

src/utils.ml
26 26
type tag = int
27 27
type longident = (string * tag) list
28 28

  
29
exception TransposeError of int*int
30

  
29 31
(** General utility functions. *)
30 32
let create_hashtable size init =
31 33
  let tbl = Hashtbl.create size in
......
69 71
let rec repeat n f x =
70 72
 if n <= 0 then x else repeat (n-1) f (f x)
71 73

  
72
let rec transpose_list ll =
73
 match ll with
74
 | []   -> []
75
 | [l]  -> List.map (fun el -> [el]) l
76
 | l::q -> 
77
   let length_l = List.length l in
78
   if not (List.for_all (fun l' -> List.length l' = length_l) q) then
79
     assert false
80
   ;
81
   List.map2 (fun el eq -> el::eq) l (transpose_list q)
74
let transpose_list ll =
75
  let rec transpose ll =
76
    match ll with
77
    | []   -> []
78
    | [l]  -> List.map (fun el -> [el]) l
79
    | l::q -> List.map2 (fun el eq -> el::eq) l (transpose q)
80
  in match ll with
81
  | []   -> []
82
  | l::q -> let length_l = List.length l in
83
	    List.iter (fun l' -> let length_l' = List.length l'
84
				 in if length_l <> length_l' then raise (TransposeError (length_l, length_l'))) q;
85
	    transpose ll
82 86

  
83 87
let rec filter_upto p n l =
84 88
 if n = 0 then [] else

Also available in: Unified diff