> module Main where > import IO > import Distributed > data Msg = Ping [Int] | Pong [Int] | Quit deriving (Read,Show) > instance Serialize Msg > main = do > hSetBuffering stdout NoBuffering > Distributed.start (do > me <- self > pid <- spawn (reader me) > valStr <- proc $ myGetVarDefault "CNT" "1000" > let val = ((read valStr) :: Int) > loop pid val > pid Quit > halt > ) "" > loop :: Pid -> Int -> DIO Msg () > loop _ 0 = return () > loop pid (i+1) = do > pid Ping [0..i] > proc $ putStr "." > receive (\v -> case v of > Pong _ -> return () > ) > loop pid i > reader :: Pid -> DIO Msg () > reader parent = do > receive (\v -> case v of > Ping i -> do > proc $ putStr "#" > parent Pong i > reader parent > Quit -> do > return () > )