我写了一个生成 in 列表的randomized ints函数OCaml。
let create_shuffled_int_list n =
Random.self_init;
let rec create n' acc =
if n' = 0 then acc
else
create (n'-1) (acc @ [Random.int (n/2)])
in
create n [];;
当我尝试生成10000整数时,它给出了Exception: RangeError: Maximum call stack size exceeded.错误。
但是,我相信这个功能,我用过tail-recursion,它应该不会stackoverflow出错,对吧?
任何想法?