Go to the first, previous, next, last section, table of contents.

Converting `Dialogue' I/O

In most cases, it's really easy to convert from Haskell 1.2's I/O to the monadic I/O of Haskell 1.3.
  1. The type `Dialogue' usually can become `IO ()'.
  2. Change `readChan stdin' to `getContents'.
  3. Change `appendChan stdout' to `putStr', which is equivalent to `hPutStr stdout'. Change `appendChan stderr' to `hPutStr stderr'.
  4. You need to `import IO' to do any interesting I/O; in particular, anything to do with `Handle's.
  5. You need to `import System' if you used `getArgs', `getEnv', or `getProgName'.
  6. Assuming continuation-style `Dialogue' code, change `... exit done $' to `... >>'. Change `... exit $ \ foo ->' to `... >>= \ foo ->'.
  7. Sometimes, when you change your `main' routine to "do" notation, you'll get an error message like:
    "Main.hs", line 32: No instance for: Prelude.MonadZero IO
        "Main.hs", line 32: in a do statement
    
    This probably means that you need to "twiddle" some patterns; e.g., I added the twiddle to the `getArgs'-related pattern here:
    main = do
        ~[a1] <- getArgs
        let x = fst (head ((reads::ReadS Int) a1)
        putStr (show (result x))
    
  8. If you had any functions named `(>>)', `(>>=)', or `return', change them to something else.
  9. If you used the `StatusFile' I/O request, do something else. No exact equivalent exists in 1.3.

Go to the first, previous, next, last section, table of contents.