OCaml implements map over lists like so:
let[@tail_mod_cons] rec map f = function [] -> [] | [a1] -> let r1 = f a1 in [r1] | a1::a2::l -> let r1 = f a1 in let r2 = f a2 in r1::r2::map f l
To me this seems equivalent to this:
let[@tail_mod_cons] rec map f = function [] -> [] | a1::l -> let r1 = f a1 in r1::map f l
Why is map
implemented the way that it is, rather than the more concise way?
This question is a follow on from Tail recursive List.map