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

ocaml tail-recursive functions

$
0
0

I'm running Ocaml using utop, when I run the below function on a very long input:

let string_to_list str =  let rec loop i limit =    if i = limit then []    else (String.get str i) :: (loop (i + 1) limit)  in  loop 0 (String.length str);;

it returns the following error:

Stack overflow during evaluation (looping recursion?).

What would be the tail-recursive version of the function?


Viewing all articles
Browse latest Browse all 531

Trending Articles



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