Input Processing Loops in Haskell

Mark Conway Wirt
Tue, 13 Nov 2001 10:00:11 -0500

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;

the above code could be used in an input-processing loop.  The question is,
is something like this possible in Haskell?  I realize that you can
use recursive calls to do something similar:

f a 
 | a == GET_OUT   = a
 | otherwise      = f ( g a)

The problem is stack-growth.  I can't figure out a way (I'm sort of a newbie)
to so something like the above without growing my stack infinitely.
I've seen something called "tail-recursion" discussed in comp.lang.functional
that *may* be relevant, but I can't find any concise explanation of this

So, is this possible in either Haskell or Haskell+ghc extensions?