Hacker News new | ask | show | jobs
by mkeoliya 1394 days ago
> of course, fold right is the more general operator, as you can implement fold left in terms of fold right.

The other way works too: fold right can be implemented in terms of fold left. Here's an approach using continuations in OCaml:

  let fold_right f z xs = (List.fold_left (fun kont x -> (fun y -> kont (f x y))) Fun.id xs) z;;