1 {-# OPTIONS -fno-implicit-prelude #-}
2 -----------------------------------------------------------------------------
5 -- Copyright : (c) The University of Glasgow 2001
6 -- License : BSD-style (see the file libraries/base/LICENSE)
8 -- Maintainer : libraries@haskell.org
9 -- Stability : provisional
10 -- Portability : portable
12 -- The standard IO library.
14 -----------------------------------------------------------------------------
17 Handle, -- abstract, instance of: Eq, Show.
18 HandlePosn(..), -- abstract, instance of: Eq, Show.
20 IOMode(ReadMode,WriteMode,AppendMode,ReadWriteMode),
21 BufferMode(NoBuffering,LineBuffering,BlockBuffering),
22 SeekMode(AbsoluteSeek,RelativeSeek,SeekFromEnd),
24 stdin, stdout, stderr, -- :: Handle
26 openFile, -- :: FilePath -> IOMode -> IO Handle
27 hClose, -- :: Handle -> IO ()
28 hFileSize, -- :: Handle -> IO Integer
29 hIsEOF, -- :: Handle -> IO Bool
32 hSetBuffering, -- :: Handle -> BufferMode -> IO ()
33 hGetBuffering, -- :: Handle -> IO BufferMode
34 hFlush, -- :: Handle -> IO ()
35 hGetPosn, -- :: Handle -> IO HandlePosn
36 hSetPosn, -- :: HandlePosn -> IO ()
37 hSeek, -- :: Handle -> SeekMode -> Integer -> IO ()
39 hTell, -- :: Handle -> IO Integer
41 hWaitForInput, -- :: Handle -> Int -> IO Bool
42 hReady, -- :: Handle -> IO Bool
43 hGetChar, -- :: Handle -> IO Char
44 hGetLine, -- :: Handle -> IO [Char]
45 hLookAhead, -- :: Handle -> IO Char
46 hGetContents, -- :: Handle -> IO [Char]
47 hPutChar, -- :: Handle -> Char -> IO ()
48 hPutStr, -- :: Handle -> [Char] -> IO ()
49 hPutStrLn, -- :: Handle -> [Char] -> IO ()
50 hPrint, -- :: Show a => Handle -> a -> IO ()
51 hIsOpen, hIsClosed, -- :: Handle -> IO Bool
52 hIsReadable, hIsWritable, -- :: Handle -> IO Bool
53 hIsSeekable, -- :: Handle -> IO Bool
55 isAlreadyExistsError, isDoesNotExistError, -- :: IOError -> Bool
56 isAlreadyInUseError, isFullError,
57 isEOFError, isIllegalOperation,
58 isPermissionError, isUserError,
60 ioeGetErrorString, -- :: IOError -> String
61 ioeGetHandle, -- :: IOError -> Maybe Handle
62 ioeGetFileName, -- :: IOError -> Maybe FilePath
64 try, -- :: IO a -> IO (Either IOError a)
65 bracket, -- :: IO a -> (a -> IO b) -> (a -> IO c) -> IO c
66 bracket_, -- :: IO a -> (a -> IO b) -> IO c -> IO c
68 -- Non-standard extension (but will hopefully become standard with 1.5) is
69 -- to export the Prelude io functions via IO (in addition to exporting them
70 -- from the prelude...for now.)
71 IO, -- instance MonadFix
72 FilePath, -- :: String
74 ioError, -- :: IOError -> IO a
75 userError, -- :: String -> IOError
76 catch, -- :: IO a -> (IOError -> IO a) -> IO a
77 interact, -- :: (String -> String) -> IO ()
79 putChar, -- :: Char -> IO ()
80 putStr, -- :: String -> IO ()
81 putStrLn, -- :: String -> IO ()
82 print, -- :: Show a => a -> IO ()
83 getChar, -- :: IO Char
84 getLine, -- :: IO String
85 getContents, -- :: IO String
86 readFile, -- :: FilePath -> IO String
87 writeFile, -- :: FilePath -> String -> IO ()
88 appendFile, -- :: FilePath -> String -> IO ()
89 readIO, -- :: Read a => String -> IO a
90 readLn, -- :: Read a => IO a
93 hPutBuf, -- :: Handle -> Ptr a -> Int -> IO ()
94 hGetBuf, -- :: Handle -> Ptr a -> Int -> IO Int
97 fixIO, -- :: (a -> IO a) -> IO a
100 hSetEcho, -- :: Handle -> Bool -> IO ()
101 hGetEcho, -- :: Handle -> IO Bool
103 hIsTerminalDevice, -- :: Handle -> IO Bool
107 #ifdef __GLASGOW_HASKELL__
109 import GHC.IOBase -- Together these four Prelude modules define
110 import GHC.Handle -- all the stuff exported by IO for the GHC version
112 import GHC.ST ( fixST )
124 import System.IO.Error
126 -- -----------------------------------------------------------------------------
130 putChar :: Char -> IO ()
131 putChar c = hPutChar stdout c
133 putStr :: String -> IO ()
134 putStr s = hPutStr stdout s
136 putStrLn :: String -> IO ()
137 putStrLn s = do putStr s
140 print :: Show a => a -> IO ()
141 print x = putStrLn (show x)
144 getChar = hGetChar stdin
147 getLine = hGetLine stdin
149 getContents :: IO String
150 getContents = hGetContents stdin
152 interact :: (String -> String) -> IO ()
153 interact f = do s <- getContents
156 readFile :: FilePath -> IO String
157 readFile name = openFile name ReadMode >>= hGetContents
159 writeFile :: FilePath -> String -> IO ()
160 writeFile name str = do
161 hdl <- openFile name WriteMode
165 appendFile :: FilePath -> String -> IO ()
166 appendFile name str = do
167 hdl <- openFile name AppendMode
171 readLn :: Read a => IO a
172 readLn = do l <- getLine
176 -- raises an exception instead of an error
177 readIO :: Read a => String -> IO a
178 readIO s = case (do { (x,t) <- reads s ;
182 [] -> ioError (userError "Prelude.readIO: no parse")
183 _ -> ioError (userError "Prelude.readIO: ambiguous parse")
184 #endif /* __HUGS__ */
186 hReady :: Handle -> IO Bool
187 hReady h = hWaitForInput h 0
189 hPutStrLn :: Handle -> String -> IO ()
190 hPutStrLn hndl str = do
194 hPrint :: Show a => Handle -> a -> IO ()
195 hPrint hdl = hPutStrLn hdl . show
197 -- ---------------------------------------------------------------------------
200 #ifdef __GLASGOW_HASKELL__
201 fixIO :: (a -> IO a) -> IO a
202 fixIO m = stToIO (fixST (ioToST . m))