[Haskell] Monadic Loops
Arjan van IJzendoorn
afie at cs.uu.nl
Thu Jun 17 07:59:01 EDT 2004
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
More information about the Haskell
mailing list