let make_uniform min max n =
  let open Result in
  if min >= max then
    fail (sprintf "minimum %.3f must be strictly less than maximum %.3f" min max)
  else if n < 1 then
    fail (sprintf "cannot create histogram with %d bins" n)
  else begin
    let delt = (max -. min) /. (Float.of_int n) in
    let bins = Array.init (n+1) (fun i -> min +. (delt *. Float.of_int i)) in
    bins.(Array.length bins - 1) <- max;
    Result.of_option  (make Pervasives.compare (Array.to_list bins))
      ~error:"not ordered"
  end