Skip to content

Instantly share code, notes, and snippets.

@rrichardson
Created May 12, 2010 15:33
Show Gist options
  • Save rrichardson/398727 to your computer and use it in GitHub Desktop.
Save rrichardson/398727 to your computer and use it in GitHub Desktop.
forMpar :: [a] -> (a -> IO b) -> IO [b]
forMpar xs fun = do
sem <- newQSem (length xs)
c <- newChan
forM_ xs (\x -> forkIO $ wrap fun x c sem)
waitQSem sem
collect (length xs) c []
where wrap f item chan qsem = f item >>= writeChan chan >> signalQSem qsem
collect 0 chan acc = return acc
collect count chan acc = do !i <- readChan chan; collect (count - 1) chan i::acc
Network/BsonRPC/Util.hs:95:0:
Occurs check: cannot construct the infinite type: b = [b]
When generalising the type(s) for `forMpar'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment