module Main where import Control.Concurrent main :: IO ThreadId main = do theTalk <- newEmptyMVar :: IO ( MVar String ) forkIO( chris_proc theTalk ) forkIO( kelly_proc theTalk ) kelly_proc :: MVar String -> IO () kelly_proc theTalk = do talk <- takeMVar theTalk putStrLn talk putMVar theTalk "Hello, can I speak to Chris?" yield talk <- takeMVar theTalk putStrLn talk putMVar theTalk "Chris, this is Kelly from ACME company\n and we are having a special on..." yield talk <- takeMVar theTalk putStrLn talk putMVar theTalk "But this is a great deal and ..." yield talk <- takeMVar theTalk putStrLn talk chris_proc :: MVar String -> IO () chris_proc theTalk = do putMVar theTalk "Hello?" yield talk <- takeMVar theTalk putStrLn talk putMVar theTalk "This is Chris" yield talk <- takeMVar theTalk putStrLn talk putMVar theTalk "Excuse me, but I am really not interested." yield talk <- takeMVar theTalk putStrLn talk putMVar theTalk "I am hanging up now;\n goodbye." return ()