Requesting a larger stack using Ocaml.
"Douglas Lewit [email protected] [ocaml_beginners]" <[email protected]> Fri, 8 Apr 2016 12:35:43 -0500
| Newsgroups | gmane.comp.lang.ocaml.beginners |
|---|---|
| Message-ID | <CAM0XMJSSkpJ_Kh2da7QkP3jnLECXVttkiLkgBonVzwPoSFePFQ@mail.gmail.com> |
Hi, I often invoke Java's compiler from the command line in Terminal. If I'm implementing a Java program with a lot of heavy recursion in it, I can apply the -Xss option to request more stack memory. The default stack size for Java is usually 500 Kb of RAM. But this can be changed by using that option. For example: *java -Xss4m Fibonacci* Then my Fibonacci java program will have a larger than normal stack. Rather than the default of 0.5 megs, now the program can use 4 megs of memory. That's great! The Java user has the option of increasing the size of the stack. I've been playing around with a lot of recursion on lists in Ocaml. And normally Ocaml handles recursion very nicely and very quickly. But there are exceptions. I created this one function where I add up the float values in an approximation of the unit probability function defined on [0, 1]. Then I add up the values and divide by the number of values to get the average. ( Ideally the average is 0.5, but that's only if you use an infinitely long list of values from that distribution. ) Then I put the averages into another list. If I'm requesting about 100,000 such values, there's no problem. But for 1,000,000 values Ocaml returns a warning message about a possible looping recursion! My function does indeed work for values around 100,000, so my program logic is correct. But it seems that Ocaml's stack blows up if I want to create a list with a million of those floating point values in it. So is there some command line option that I can use to tell Ocaml's compiler ( and interpreter ) that I want to use a larger stack? Thanks for the feedback. Best, Douglas.