@@ -21,7 +21,7 @@ instance Binary a => Binary (SizedList a) where
2121
2222-- Copied from Data.Binary
2323getMany :: Binary a => Int -> Get [a]
24−getMany n = go [] n
24+getMany = go []
2525 where
2626 go xs 0 = return $! reverse xs
2727 go xs i = do x <- get
@@ -38,22 +38,19 @@ counter :: Process ()
3838counter = go 0
3939 where
4040 go :: Int -> Process ()
41− go !n = do
42− msg <- receiveWait
43− [ match $ \xs -> return . Left . size $ (xs :: SizedList Int)
44− , match $ \them -> return . Right $ them
41+ go !n =
42+ receiveWait
43+ [ match $ \xs -> go (n + size (xs :: SizedList Int))
44+ , match $ \them -> send them n >> go 0
4545 ]
46− case msg of
47− Left n' -> go (n + n')
48− Right them -> send them n >> go 0
4946
5047count :: (Int, Int) -> ProcessId -> Process ()
51−count (packets, size) them = do
48+count (packets, sz) them = do
5249 us <- getSelfPid
53− replicateM_ packets $ send them (nats size)
50+ replicateM_ packets $ send them (nats sz)
5451 send them us
5552 n' <- expect
56− liftIO $ print (packets * size, n' == packets * size)
53+ liftIO $ print (packets * sz, n' == packets * sz)
5754
5855initialProcess :: String -> Process ()
5956initialProcess "SERVER" = do
@@ -61,7 +58,7 @@ initialProcess "SERVER" = do
6158 liftIO $ BSL.writeFile "counter.pid" (encode us)
6259 counter
6360initialProcess "CLIENT" = do
64− n <- liftIO $ getLine
61+ n <- liftIO getLine
6562 them <- liftIO $ decode <$> BSL.readFile "counter.pid"
6663 count (read n) them
6764