On Thu, 16 Apr 1998, S. Alexander Jacobson wrote:

> All that being said, we can say that there are certain properties that 
> all haskell functions must fulfill.  For example a recursive function
> should never call itself with the arguments that it recieved.
> 
> e.g. myFunction 2 3 should not make a recursive call to myFunction 2 3

You can't even say that, since things like

cycle :: [a] -> [a]
cycle xs = xs ++ cycle xs

are very useful in a lazy functional language since only the portion of
the list that is actually used in the computation will be constructed.
(eg take 20 (cycle " ") to get a string of 20 spaces.)
So you could say `a recursive function should not call itself on the
right-hand side with exactly the same arguments on the left hand side as
the argument of an operator/function is strict',

eg, not f x y = 1 + f x y   because + is strict in its right argument (&
its left but that's not relevant)

but whether or not a function is strict in one argument may depend on the
others and is undecidable in general. (I admit I can't think of a
convincing example of the top of my head.) 

> It would be really useful if a debugger/interpreter could detect when
> this type of error happens and generates an error message documenting
> the location of such an infinite loop call.

What would be very useful would be just a tally of how many times a
function f is called with the same arguments when a program being
debugged & looping is aborted, on the grounds that things like cycle
should be dwarfed by the real cause of the infinite loop.

cheers, dave
-------------------------------------------------------------------------
email: [EMAIL PROTECTED]      One of the endearing things about
www.cs.bris.ac.uk/~tweed/pi.htm mathematicians is the extent to which
work tel: (0117) 9545104        they will go to avoid doing any real work



Reply via email to