17 Jun
2004
17 Jun
'04
11:59 a.m.
Hello, Vivian uses this while function: while test body = do (cond,res) <- body if (test cond) then do rs <- while test body return (res:rs) else return [res]
However, when I run the program, the interpreter falls over after a few thousand iterations, running out of space.
Maybe making it tail-recursive helps. Let me think...... untested code ahead: while test body = do res <- funnyWhile test body [] return (reverse res) funnyWhile test body revResult = do (cond, res) <- body if test cond then while test body (res:revResult) else return revResult Greetings, Arjan