Why wasn't OCaml List.fold_right implemented as tail-recursive?

List.fold_rightnot tail-recursiveas indicated here http://caml.inria.fr/pub/docs/manual-ocaml/libref/List.html

My question is: why was List.fold_rightnot implemented how tail-recursive?

I think it’s not difficult to do.

let rev l = 
  let rec revr acc = function
    | [] -> acc
    | hd::tl -> revr (hd::acc) tl
  in 
  revr [] l;;

let fold_right f l b =
  let rev_l = rev l 
  in 
  let rec folder_rr acc = function
    | [] -> acc
    | hd::tl -> folder_rr (f hd acc) tl
  in 
  folder_rr b rev_l;;

I also found a number of non functions in the library tail-recursive, while they can be implemented as tail-recursive. How did the manufacturer make such decisions?

+5
source share
2 answers

fold_right , , . , ( , ) , .

, fold_right .. , , Extlib . , , non-tailrec , tailrec, , - cons ( ).

+8

, , . :

OCaml std lib - ?

, . , , .

+8

All Articles