Hi,
attached is an ML program "tailrecursive.ML" that calculates !n = n * (n-1) * (n-2) * ... * 1 by rewriting. Nevertheless, it doesn't matter so much what the program does, but that calls to the function "testfac" lead to a stack overflow, although the relevant functions "lookup", "weak", "weak_last", "strong", "strong_last" are all clearly tail recursive.
Running "testfac 100" succeeds, whereas evaluating "testfac 400" leads to the output below:
Poly/ML RTS version I386-4.1.3 (14:28:57 Sep 30 2002) Copyright (c) 2002 CUTS and contributors. Running with heap parameters (h=10240K,ib=2048K,ip=100%,mb=6144K,mp=20%) WARNING:/usr/lib/poly/ML_dbase: Write permission denied. WARNING:/usr/lib/poly/ML_dbase: Opened for reading only. Mapping /usr/lib/poly/ML_dbase Poly/ML 4.1.3 Release
use "tailrecursive.ML";
.....
testfac 400;
calc fac in native ML calc fac by rewriting Warning - Increasing stack from 147456 to 294912 bytes Warning - Increasing stack from 294912 to 589824 bytes Warning - Increasing stack from 589824 to 1179648 bytes Warning - Increasing stack from 1179648 to 2359296 bytes Warning - Increasing stack from 2359296 to 4718592 bytes Warning - Increasing stack from 4718592 to 9437184 bytes Warning - Increasing stack from 9437184 to 18874368 bytes Warning - Increasing stack from 18874368 to 37748736 bytes Warning - Increasing stack from 37748736 to 67108860 bytes Warning - Stack limit reached - interrupting process Exception- Interrupt raised
Is this a bug in Poly/ML? Does anybody know a workaround?
I tried the same with Standard ML of New Jersey, 110.46, and even "testfac 7000" is unproblematic for SML/NJ.
Any help with / thoughts on this would be much appreciated,
Steven