List.map
この件について更に無意味に
List.map
の実装を覗いてみる.
let rec map f = function [] -> [] | a::l -> let r = f a in r :: map f lついでに,実験.
Objective Caml version 3.09.3 # let rec upto n l = if n < 0 then l else upto (n-1) (n::l);; val upto : int -> int list -> int list = <fun> # List.map ignore (upto 50000 []);; Stack overflow during evaluation (looping recursion?). # let rec map f = function [] -> [] | a::l -> f a::map f l;; val map : ('a -> 'b) -> 'a list -> 'b list = <fun> # map ignore (upto 50000 []);; - : unit list = [(); (); (); (); (); (); (); (); (); (); (); (); ... ]この結果から察するに,
List.map
は効率よりも順序を意識して実装されているような….