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

Tail recursive zip function

$
0
0

I have a function called zip_with_2_fs. I am trying to make it tail recursive (zip_with_2_fs_tr) but I don't really understand what I am doing. I am new to Ocaml and would like to develop a deeper understanding of tail recursion and helper functions.

let rec zip_with_2_fs fx fy xs ys = match (xs, ys) with  | ([], []) -> []  | ([], _) -> []  | (_, []) -> []  | (xh::xt, yh::yt) -> (fx xh, fy yh)::zip_with_2_fs fx fy xt yt;;

How would I go about fixing this?

let zip_with_2_fs_tr fx fy xs ys =  let rec helper fxx fy xss yss =    match (xs, ys) with    | ([], []) -> []    | ([], _) -> []    | (_, []) -> []    | (xh::xt, yh::yt) -> (fx xh, fy yh)::helper fx fy xt yt  in helper fx fy xs ys;;

Viewing all articles
Browse latest Browse all 531

Trending Articles



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