Re: Requesting a larger stack using Ocaml.
"Kenneth Miller [email protected] [ocaml_beginners]" <[email protected]> Fri, 8 Apr 2016 17:42:27 +0000 (UTC)
| Newsgroups | gmane.comp.lang.ocaml.beginners |
|---|---|
| Message-ID | <[email protected]> |
You'll want to look into tail recursion so that you can get the compiler to rewrite your recursive definitions as a loop on your behalf. Tail recursion is a way to eliminate the need to allocate additional stack space. You can read about it from the relevant online literature.
On Friday, April 8, 2016 1:35 PM, "Douglas Lewit [email protected] [ocaml_beginners]" <[email protected]> wrote:
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.
#yiv9644914608 #yiv9644914608 -- #yiv9644914608ygrp-mkp {border:1px solid #d8d8d8;font-family:Arial;margin:10px 0;padding:0 10px;}#yiv9644914608 #yiv9644914608ygrp-mkp hr {border:1px solid #d8d8d8;}#yiv9644914608 #yiv9644914608ygrp-mkp #yiv9644914608hd {color:#628c2a;font-size:85%;font-weight:700;line-height:122%;margin:10px 0;}#yiv9644914608 #yiv9644914608ygrp-mkp #yiv9644914608ads {margin-bottom:10px;}#yiv9644914608 #yiv9644914608ygrp-mkp .yiv9644914608ad {padding:0 0;}#yiv9644914608 #yiv9644914608ygrp-mkp .yiv9644914608ad p {margin:0;}#yiv9644914608 #yiv9644914608ygrp-mkp .yiv9644914608ad a {color:#0000ff;text-decoration:none;}#yiv9644914608 #yiv9644914608ygrp-sponsor #yiv9644914608ygrp-lc {font-family:Arial;}#yiv9644914608 #yiv9644914608ygrp-sponsor #yiv9644914608ygrp-lc #yiv9644914608hd {margin:10px 0px;font-weight:700;font-size:78%;line-height:122%;}#yiv9644914608 #yiv9644914608ygrp-sponsor #yiv9644914608ygrp-lc .yiv9644914608ad {margin-bottom:10px;padding:0 0;}#yiv9644914608 #yiv9644914608actions {font-family:Verdana;font-size:11px;padding:10px 0;}#yiv9644914608 #yiv9644914608activity {background-color:#e0ecee;float:left;font-family:Verdana;font-size:10px;padding:10px;}#yiv9644914608 #yiv9644914608activity span {font-weight:700;}#yiv9644914608 #yiv9644914608activity span:first-child {text-transform:uppercase;}#yiv9644914608 #yiv9644914608activity span a {color:#5085b6;text-decoration:none;}#yiv9644914608 #yiv9644914608activity span span {color:#ff7900;}#yiv9644914608 #yiv9644914608activity span .yiv9644914608underline {text-decoration:underline;}#yiv9644914608 .yiv9644914608attach {clear:both;display:table;font-family:Arial;font-size:12px;padding:10px 0;width:400px;}#yiv9644914608 .yiv9644914608attach div a {text-decoration:none;}#yiv9644914608 .yiv9644914608attach img {border:none;padding-right:5px;}#yiv9644914608 .yiv9644914608attach label {display:block;margin-bottom:5px;}#yiv9644914608 .yiv9644914608attach label a {text-decoration:none;}#yiv9644914608 blockquote {margin:0 0 0 4px;}#yiv9644914608 .yiv9644914608bold {font-family:Arial;font-size:13px;font-weight:700;}#yiv9644914608 .yiv9644914608bold a {text-decoration:none;}#yiv9644914608 dd.yiv9644914608last p a {font-family:Verdana;font-weight:700;}#yiv9644914608 dd.yiv9644914608last p span {margin-right:10px;font-family:Verdana;font-weight:700;}#yiv9644914608 dd.yiv9644914608last p span.yiv9644914608yshortcuts {margin-right:0;}#yiv9644914608 div.yiv9644914608attach-table div div a {text-decoration:none;}#yiv9644914608 div.yiv9644914608attach-table {width:400px;}#yiv9644914608 div.yiv9644914608file-title a, #yiv9644914608 div.yiv9644914608file-title a:active, #yiv9644914608 div.yiv9644914608file-title a:hover, #yiv9644914608 div.yiv9644914608file-title a:visited {text-decoration:none;}#yiv9644914608 div.yiv9644914608photo-title a, #yiv9644914608 div.yiv9644914608photo-title a:active, #yiv9644914608 div.yiv9644914608photo-title a:hover, #yiv9644914608 div.yiv9644914608photo-title a:visited {text-decoration:none;}#yiv9644914608 div#yiv9644914608ygrp-mlmsg #yiv9644914608ygrp-msg p a span.yiv9644914608yshortcuts {font-family:Verdana;font-size:10px;font-weight:normal;}#yiv9644914608 .yiv9644914608green {color:#628c2a;}#yiv9644914608 .yiv9644914608MsoNormal {margin:0 0 0 0;}#yiv9644914608 o {font-size:0;}#yiv9644914608 #yiv9644914608photos div {float:left;width:72px;}#yiv9644914608 #yiv9644914608photos div div {border:1px solid #666666;height:62px;overflow:hidden;width:62px;}#yiv9644914608 #yiv9644914608photos div label {color:#666666;font-size:10px;overflow:hidden;text-align:center;white-space:nowrap;width:64px;}#yiv9644914608 #yiv9644914608reco-category {font-size:77%;}#yiv9644914608 #yiv9644914608reco-desc {font-size:77%;}#yiv9644914608 .yiv9644914608replbq {margin:4px;}#yiv9644914608 #yiv9644914608ygrp-actbar div a:first-child {margin-right:2px;padding-right:5px;}#yiv9644914608 #yiv9644914608ygrp-mlmsg {font-size:13px;font-family:Arial, helvetica, clean, sans-serif;}#yiv9644914608 #yiv9644914608ygrp-mlmsg table {font-size:inherit;font:100%;}#yiv9644914608 #yiv9644914608ygrp-mlmsg select, #yiv9644914608 input, #yiv9644914608 textarea {font:99% Arial, Helvetica, clean, sans-serif;}#yiv9644914608 #yiv9644914608ygrp-mlmsg pre, #yiv9644914608 code {font:115% monospace;}#yiv9644914608 #yiv9644914608ygrp-mlmsg * {line-height:1.22em;}#yiv9644914608 #yiv9644914608ygrp-mlmsg #yiv9644914608logo {padding-bottom:10px;}#yiv9644914608 #yiv9644914608ygrp-msg p a {font-family:Verdana;}#yiv9644914608 #yiv9644914608ygrp-msg p#yiv9644914608attach-count span {color:#1E66AE;font-weight:700;}#yiv9644914608 #yiv9644914608ygrp-reco #yiv9644914608reco-head {color:#ff7900;font-weight:700;}#yiv9644914608 #yiv9644914608ygrp-reco {margin-bottom:20px;padding:0px;}#yiv9644914608 #yiv9644914608ygrp-sponsor #yiv9644914608ov li a {font-size:130%;text-decoration:none;}#yiv9644914608 #yiv9644914608ygrp-sponsor #yiv9644914608ov li {font-size:77%;list-style-type:square;padding:6px 0;}#yiv9644914608 #yiv9644914608ygrp-sponsor #yiv9644914608ov ul {margin:0;padding:0 0 0 8px;}#yiv9644914608 #yiv9644914608ygrp-text {font-family:Georgia;}#yiv9644914608 #yiv9644914608ygrp-text p {margin:0 0 1em 0;}#yiv9644914608 #yiv9644914608ygrp-text tt {font-size:120%;}#yiv9644914608 #yiv9644914608ygrp-vital ul li:last-child {border-right:none !important;}#yiv9644914608