[Haskell] Monadic Loops

Vivian McPhail vivian.mcphail at paradise.net.nz
Thu Jun 17 05:16:21 EDT 2004


Hi, 

I've implemented a Neural Net simulator which needs to repeat a training loop many times. For this I used a 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. I think that this is because the Monadic implementation of the while loop actually nests functions of type (a -> M b) and there is a maximum ?stack size. 

Is there a better way to implement (possibly infinite) loops in Haskell? 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org//pipermail/haskell/attachments/20040617/dd02458b/attachment.htm


More information about the Haskell mailing list