[Haskell-cafe] do you have to use fix with forkio?

Derek Elkins derek.a.elkins at gmail.com
Sat Mar 7 17:27:17 EST 2009

On Sat, 2009-03-07 at 23:12 +0100, Martijn van Steenbergen wrote:
> Derek Elkins wrote:
> > Both are poorish style.
> > 
> > reader <- forkIO $ forever $ do (nr', line) <- readChan; when (nr /= nr') $ putStrLn hdl line
> This is fine assuming you always want to re-enter the loop. If you want 
> to loop conditionally (which is most often the case), forever isn't 
> going to work, unless you use exceptions.

If you are doing something else, use something else.  This makes it
clear that you -aren't- going to break out (non-exceptionally), i.e. the
control flow is more obvious in this code than in the other versions.
By your logic 'map' would be bad because not everything is a map, of
course, this is precisely why using map, when applicable, is good.

More information about the Haskell-Cafe mailing list