Quantcast
Channel: Active questions tagged ocaml - Stack Overflow
Viewing all articles
Browse latest Browse all 527

Why does OCaml implement List.map with a special case for a singleton?

$
0
0

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


Viewing all articles
Browse latest Browse all 527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>