[Haskell-cafe] 1st attempt at parallelizing

Felipe Lessa felipe.lessa at gmail.com
Mon Jul 26 18:29:04 EDT 2010


2010/7/26 Felipe Lessa <felipe.lessa at gmail.com>:
> downloader :: TChan (Maybe Page) -> TChan (Page, Info) -> IO ()
> downloader in out = do
>  mp <- atomically (readTChan in)
>  case mp of
>    Nothing -> return ()
>    Just p -> download p >>= atomically . writeTChan out

Oops!  Of course there should be recursion here!  (This is a bug the
typechecker probably wouldn't catch.)

downloader :: TChan (Maybe Page) -> TChan (Page, Info) -> IO ()
downloader in out = do
 mp <- atomically (readTChan in)
 case mp of
   Nothing -> return ()
   Just p -> download p >>= atomically . writeTChan out >> downloader in out

Cheers,

-- 
Felipe.


More information about the Haskell-Cafe mailing list