3 FilePath, IOError, fail, userError, catch,
4 putChar, putStr, putStrLn, print,
5 getChar, getLine, getContents, interact,
6 readFile, writeFile, appendFile, readIO, readLn
14 type FilePath = String
16 data IOError -- The internals of this type are system dependent
18 instance Show IOError where ...
19 instance Eq IOError where ...
23 fail :: IOError -> IO a
26 userError :: String -> IOError
27 userError = primUserError
29 catch :: IO a -> (IOError -> IO a) -> IO a
36 -- this guy can go in either monad
37 primFail :: Exception -> ST s a
38 primFail err = ST (\ s -> primRaise err)
42 putChar :: Char -> IO ()
45 putStr :: String -> IO ()
46 putStr s = mapM_ putChar s
48 putStrLn :: String -> IO ()
49 putStrLn s = do putStr s
52 print :: Show a => a -> IO ()
53 print x = putStrLn (show x)
56 getContents = primGetChar
59 getLine = do c <- getChar
60 if c == '\n' then return "" else
64 getContents :: IO String
65 getContents = primGetContents
67 interact :: (String -> String) -> IO ()
68 interact f = do s <- getContents
71 readFile :: FilePath -> IO String
72 readFile = primReadFile
74 writeFile :: FilePath -> String -> IO ()
75 writeFile = primWriteFile
77 appendFile :: FilePath -> String -> IO ()
78 appendFile = primAppendFile
81 -- raises an exception instead of an error
82 readIO :: Read a => String -> IO a
83 readIO s = case [x | (x,t) <- reads s, ("","") <- lex t] of
85 [] -> fail (userError "PreludeIO.readIO: no parse")
87 "PreludeIO.readIO: ambiguous parse")
90 readLn :: Read a => IO a
91 readLn = do l <- getLine