7318cc7ac91f6b48bf77e89128fc427f7447ed4d
[ghc-hetmet.git] / ghc / misc / examples / io / io018 / Main.hs
1 import IO -- 1.3
2
3 import System(getArgs)
4
5 main =   getArgs                            >>=        \ [user,host] ->
6          let username = (user ++ "@" ++ host) in
7          openFile username ReadWriteMode    >>=        \ cd          ->
8          hSetBuffering stdin NoBuffering    >>
9          hSetBuffering stdout NoBuffering   >>
10          hSetBuffering cd NoBuffering       >>
11          hPutStr cd speakString             >>
12          speak cd
13
14 speakString = "Someone wants to speak with you\n"
15
16 speak cd =
17          (hReady cd                         >>=        \ ready       ->
18          if ready then (hGetChar cd >>= putChar)
19          else return ()                     >>
20
21          hReady stdin                       >>=        \ ready       ->
22          if ready then (getChar >>= hPutChar cd)
23          else return ())                    >>
24
25          speak cd