[Haskell-cafe] do you have to use fix with forkio?
jonathanccast at fastmail.fm
Thu Mar 5 19:12:55 EST 2009
On Thu, 2009-03-05 at 15:36 -0800, Daryoush Mehrtash wrote:
> In this chat server implementation
> forkIO is used with fix as in:
> reader <- forkIO $ fix $ \loop -> do
> (nr', line) <- readChan chan'
> when (nr /= nr') $ hPutStrLn hdl line
> 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
But the version with fix is clearer (at least to people who have fix in
their vocabulary) and arguably better style.
More information about the Haskell-Cafe