
5 Mar
2009
5 Mar
'09
7:12 p.m.
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. jcc