Lukas Bulwahn wrote:
I was mistaken that this function is tail recursive. But I was expecting that the function can be translated to the following C code (using no stack allocations):
while (p is not Nil) do if (value of p == l) then p := p->next; else break; od if (p is Nil) then raise Error...
So, this program should not allocate any stack.
That is a different function. It doesn't return the modified list but merely checks that the item is or is not present. The equivalent, tail-recursive function in ML is:
fun test l [] = raise Fail "Not present" | test l (x::xs) = if l = x then () else test l xs;
Poly/ML detects this as tail-recursive and turns it into a loop.
David