Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

How to write fold_left in CPS?

$
0
0

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


Viewing all articles
Browse latest Browse all 12111

Trending Articles



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