Here are their definitions (from here):
let fold_left f acc seq =
let rec aux f acc seq = match seq () with
| Nil -> acc
| Cons (x, next) ->
let acc = f acc x in
aux f acc next
in
aux f acc seq
let iter f seq =
let rec aux seq = match seq () with
| Nil -> ()
| Cons (x, next) ->
f x;
aux next
in
aux seq
I would have imagined they’d be implemented directly as their inner functions are implemented, like this:
let rec fold_left f acc seq = match seq () with
| Nil -> acc
| Cons (x, next) ->
let acc = f acc x in
fold_left f acc next
let rec iter f seq = match seq () with
| Nil -> ()
| Cons (x, next) ->
f x;
iter f next
I’m pretty new at OCaml, so I’m trying to understand if I’m overlooking a behavioral difference, or if it’s to do with the style of idiomatic OCaml (or something else entirely). Thanks!