@@ -21,7 +21,7 @@ instance Binary a => Binary (SizedList a) where
22-- Copied from Data.Binary
22-- Copied from Data.Binary
23getMany :: Binary a => Int -> Get [a]
23getMany :: Binary a => Int -> Get [a]
24−getMany n = go [] n
24+getMany = go []
26 go xs 0 = return $! reverse xs
26 go xs 0 = return $! reverse xs
27 go xs i = do x <- get
27 go xs i = do x <- get
@@ -38,22 +38,19 @@ counter :: Process ()
38counter = go 0
38counter = go 0
40 go :: Int -> Process ()
40 go :: Int -> Process ()
41− go !n = do
41+ go !n =
42− msg <- receiveWait
42+ receiveWait
43− [ match $ \xs -> return . Left . size $ (xs :: SizedList Int)
43+ [ match $ \xs -> go (n + size (xs :: SizedList Int))
44− , match $ \them -> return . Right $ them
44+ , match $ \them -> send them n >> go 0
47− Left n' -> go (n + n')
48− Right them -> send them n >> go 0
50count :: (Int, Int) -> ProcessId -> Process ()
47count :: (Int, Int) -> ProcessId -> Process ()
51−count (packets, size) them = do
48+count (packets, sz) them = do
52 us <- getSelfPid
49 us <- getSelfPid
53− replicateM_ packets $ send them (nats size)
50+ replicateM_ packets $ send them (nats sz)
54 send them us
51 send them us
55 n' <- expect
52 n' <- expect
56− liftIO $ print (packets * size, n' == packets * size)
53+ liftIO $ print (packets * sz, n' == packets * sz)
58initialProcess :: String -> Process ()
55initialProcess :: String -> Process ()
59initialProcess "SERVER" = do
56initialProcess "SERVER" = do
@@ -61,7 +58,7 @@ initialProcess "SERVER" = do
61 liftIO $ BSL.writeFile "counter.pid" (encode us)
58 liftIO $ BSL.writeFile "counter.pid" (encode us)
63initialProcess "CLIENT" = do
60initialProcess "CLIENT" = do
64− n <- liftIO $ getLine
61+ n <- liftIO getLine
65 them <- liftIO $ decode <$> BSL.readFile "counter.pid"
62 them <- liftIO $ decode <$> BSL.readFile "counter.pid"
66 count (read n) them
63 count (read n) them