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

Implementation of List.of_seq

$
0
0

If we look at the source for the OCaml List module, of_seq is defined as:

let[@tail_mod_cons] rec of_seq seq =  match seq () with  | Seq.Nil -> []  | Seq.Cons (x1, seq) ->      begin match seq () with      | Seq.Nil -> [x1]      | Seq.Cons (x2, seq) -> x1 :: x2 :: of_seq seq      end

This makes perfect sense except why is the extra work performed within the function as opposed to writing the seemingly more straightforward following function?

let[@tail_mod_cons] rec of_seq seq =  match seq () with  | Seq.Nil -> []  | Seq.Cons (x1, seq) -> x1 :: of_seq seq

What insight am I missing to make this make sense?


Viewing all articles
Browse latest Browse all 527

Trending Articles



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