|
|
|
|
|
by trealira
863 days ago
|
|
Isn't that overly restrictive? Some programs are guaranteed to terminate even with mutual recursion. For example, these (obviously inefficient) functions always terminate for all values of x, since both terminate given an input of 0, and 0 is the minimum possible input to these functions. bool even(unsigned int x)
{
return (n == 0) ? true : odd(n - 1);
}
bool odd(unsigned int x)
{
return (n == 0) ? false : even(n - 1);
}
|
|
While statically verifying your snippet is possible, it is also significantly more difficult to do than enforcing rules like "all loops must have an upper limit". I also think that you'd need dependent types to make this approach viable. Your simple example is IMHO rather an exception, just having "unsigned int" parameters / return types would mostly not suffice to statically verify that a recursive method will finish or not. (plus things like global state etc.)