Even though it's already tail-recursive, It's still interesting to see a CPS version of it.
Here's the standart fold_left:
let rec myFoldLeft f acc list = match list with | [] -> acc | h :: tl -> myFoldLeft f (f h acc) tl;;
Here's an example of fold_right
let rec myFoldRightCPS f acc list cont = match list with | [] -> cont acc | h :: tl -> myFoldRightCPS f acc tl (fun t -> cont @@ f t h)
I'm using OCaml for this one