let make cmp bins =
let rec is_ordered l =
match l with
| [] -> true
| x::[] -> true
| x1::x2::l ->
match cmp x1 x2 with
| x when x < 0 -> is_ordered (x2::l)
| _ -> false
in
if is_ordered bins then
Some {cmp=cmp;
bin_limits = Array.of_list bins;
counts = Array.create (List.length bins - 1) 0.0}
else
None