Ticket #2563: exMVar.hs

File exMVar.hs, 465 bytes (added by TomMD, 6 years ago)

The program

Line 
1import Data.Digest.Pure.MD5
2import qualified Data.ByteString.Lazy as L
3import System.Environment
4import Control.Concurrent
5
6main = do
7    files <- getArgs
8    str <- newEmptyMVar
9    mapM_ (forkIO . hashAndPrint str) files
10    printNrResults (length files) str
11
12printNrResults 0 _ = return ()
13printNrResults i var = do
14        s <- takeMVar var
15        putStrLn s
16        printNrResults (i - 1) var
17
18hashAndPrint str f = do
19        bs <- L.readFile f
20        putMVar str (f ++ ": " ++ show (md5 bs))