Steven, I've had a quick look at your program and the code that's generated and it seems that the Poly/ML optimiser is attempting some tuple optimisation that is resulting in the code ceasing to be tail-recursive. I'll have to look much more closely to see exactly what is going on and how it has reached that state.
Tail-recursion removal is an optimisation and there's no guarantee that Poly/ML will not use up stack or heap space in any particular example.
Regards, David.
Steven Obua wrote:
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.