On Thu, 2009-03-05 at 16:12 -0800, Jonathan Cast wrote: > On Thu, 2009-03-05 at 15:36 -0800, Daryoush Mehrtash wrote: > > In this chat server implementation > > http://www.haskell.org/haskellwiki/Implement_a_chat_server > > > > forkIO is used with fix as in: > > > > reader <- forkIO $ fix $ \loop -> do > > > > (nr', line) <- readChan chan' > > when (nr /= nr') $ hPutStrLn hdl line > > > > loop > > > > Do you have to use fix? Or is there a way to write this with a "let"? > > You can certainly use let: > > reader <- forkIO $ let loop = do > (nr', line) <- readChan chan' > when (nr /= nr') $ hPutStrLn hdl line > loop > in loop > > But the version with fix is clearer (at least to people who have fix in > their vocabulary) and arguably better style.
Both are poorish style. reader <- forkIO $ forever $ do (nr', line) <- readChan; when (nr /= nr') $ putStrLn hdl line _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe