4 \filetitle{IO.lgs --- Implementation of the basic I/O monad}
5 \author{Andy Gill \\ University of Glasgow.\\(edited by IP)}
13 % 15-01-94 ipoole IO --> Io (to keep ghc happy)
14 % 04-09-93 ipoole #ifdef Gofer, so we can compile with hbc
16 % 02-09-93 ipoole extracted from Andy's prelude, name changes:
17 % returnIO --> unitIO, thenIO --> bindIO.
23 \end{verbatim}\end{vb}
25 This is the basic monad upon which the \verb@Job s1 s2 a@ monad is defined.
28 The Io monad, defined in terms of a Haskell Dialogue.
31 > type Io a = (a -> Dialogue) -> Dialogue
36 > ioToDialogue, processRequestIo, doneIo
41 \end{verbatim}\end{vb}\end{Dec}
44 The operation which returns a result without performing I/O.
49 > unitIo x cont = cont x
51 \end{verbatim}\end{vb}\end{Def}
54 Connect an Io operation to a continuation.
57 > bindIo :: Io a -> (a -> Io b) -> Io b
58 > bindIo m k cont = m (\ a -> k a cont)
60 \end{verbatim}\end{vb}\end{Def}
62 \begin{Def}{ioToDialogue}
63 Convert an Io to a runable Haskell Dialogue
66 > ioToDialogue :: Io a -> Dialogue
67 > ioToDialogue io = io (const (const []))
69 \end{verbatim}\end{vb}\end{Def}
71 \begin{Def}{processRequestIo}
72 Output a Haskell Request and get back the response.
75 > processRequestIo :: Request -> Io Response
76 > processRequestIo req cont ~(resp:resps) = req : cont resp resps
78 \end{verbatim}\end{vb}\end{Def}
85 > doneIo cont = \ _ -> []
87 \end{verbatim}\end{vb}\end{Def}