
I apologize if this is a bit off-topic -- I'm asking it here because if what I want to do is possible, it may only be possible with ghc extensions, as opposed to vanilla Haskell......
In many types of applications, it's common to have a loop which loops infinitely, of at least until some condition is met. For example, in C-like syntax:
for (;;;) { a = get_input(); if (a == GET_OUT) break; do_comthing(); }
You can paraphrase this in Haskell, in the IO monad, like this: loop = do { a <- get_input; if (a == gET_OUT) then return () else loop; } In GHC this won't grow any stack each time around the loop, even with optimisation off. It depends on the actual implementation of the IO monad, but I imagine the other Haskell implementations will also have this property. Cheers, Simon