This summary is provided for information only, and does not form part of the I/O definition proper. In case of inconsistency, definitions given in the main body of the I/O definition take precedence over those given here.
> infixr 1 >>, >>= -- PreludeMonadicIO
> data IOError = AlreadyExists String -- PreludeIOError > | Deadlock String > | HardwareFault String > | IllegalOperation String > | InappropriateType String > | InvalidArgument String > | NoSuchThing String > | OperationInterrupted String > | OtherError String > | PermissionDenied String > | ProtocolError String > | ResourceBusy String > | ResourceExhausted String > | ResourceVanished String > | SystemError String > | TimeExpired String > | UnsatisfiedConstraints String > | UnsupportedOperation String > | UserError String > type IO a -- PreludeMonadicIO > data Either a b = Left a | Right b -- PreludeMonadicIO > type Handle -- PreludeStdIO > type FilePath = String -- PreludeStdIO > data IOMode = ReadMode -- PreludeStdIO > | WriteMode > | AppendMode > | ReadWriteMode > data BufferMode = NoBuffering -- PreludeStdIO > | LineBuffering > | BlockBuffering (Maybe Int) > data HandlePosn -- PreludeStdIO > data SeekMode = AbsoluteSeek -- PreludeStdIO > | RelativeSeek > | SeekFromEnd > data ExitCode = ExitSuccess -- LibSystem > | ExitFailure Int > data ClockTime -- LibTime > instance Ord ClockTime -- LibTime > instance Eq ClockTime -- LibTime > instance Text ClockTime -- LibTime > data CalendarTime = -- LibTime > CalendarTime Int Int Int Int > Int Int Integer > Int Int String > Int Bool > data TimeDiff = -- LibTime > TimeDiff Int Int > Int Int Int Int Integer > deriving (Eq,Ord)
> stdin, stdout, stderr :: Handle -- PreludeStdIO
> (>>=) :: IO a -> (a -> IO b) -> IO b > (>>) :: IO a -> IO b -> IO b > accumulate :: [IO a] -> IO [a] > appendFile :: FilePath -> String -> IO () > either :: (a -> c) -> (b -> c) -> (Either a b) -> c > fail :: String -> IO a > failWith :: IOError -> IO a > getChar :: IO Char > handle :: IO a -> (IOError -> IO a) -> IO a > hClose :: Handle -> IO () > hFileSize :: Handle -> IO Integer > hFlush :: Handle -> IO () > hGetChar :: Handle -> IO Char > hGetContents :: Handle -> IO String > hGetPosn :: Handle -> IO HandlePosn > hIsBlockBuffered :: Handle -> IO (Bool,Maybe Int) > hIsClosed :: Handle -> IO Bool > hIsEOF :: Handle -> IO Bool > hIsLineBuffered :: Handle -> IO Bool > hIsNotBuffered :: Handle -> IO Bool > hIsOpen :: Handle -> IO Bool > hIsReadable :: Handle -> IO Bool > hIsSeekable :: Handle -> IO Bool > hIsWritable :: Handle -> IO Bool > hLookAhead :: Handle -> IO Char > hPutChar :: Handle -> Char -> IO () > hPutStr :: Handle -> String -> IO () > hPutText :: Text a => Handle -> a -> IO () > hReady :: Handle -> IO Bool > hSeek :: Handle -> SeekMode -> Integer -> IO () > hSetBuffering :: Handle -> BufferMode -> IO () > hSetPosn :: HandlePosn -> IO () > interact :: (String -> String) -> IO () > isEOF :: IO Bool > openFile :: FilePath -> IOMode -> IO Handle > print :: Text a => a -> IO () > putChar :: Char -> IO () > putStr :: String -> IO () > putText :: Text a => a -> IO () > readFile :: FilePath -> IO String > return :: a -> IO a > sequence :: [IO a] -> IO () > try :: IO a -> IO (Either IOError a) > writeFile :: FilePath -> String -> IO ()
> addToClockTime :: TimeDiff -> ClockTime -> ClockTime > diffClockTimes :: ClockTime -> ClockTime -> TimeDiff > createDirectory :: FilePath -> IO () > exitWith :: ExitCode -> IO a > getArgs :: IO [String] > getClockTime :: IO ClockTime > getCPUTime :: IO Integer > getCurrentDirectory :: IO FilePath > getDirectoryContents :: FilePath -> IO [FilePath] > getEnv :: String -> IO String > getProgName :: IO String > removeDirectory :: FilePath -> IO () > removeFile :: FilePath -> IO () > renameDirectory :: FilePath -> FilePath -> IO () > renameFile :: FilePath -> FilePath -> IO () > setCurrentDirectory :: FilePath -> IO () > setUserInterrupt :: Maybe (IO ()) -> IO (Maybe (IO ())) > system :: String -> IO ExitCode > toCalendarTime :: ClockTime -> CalendarTime > toUTCTime :: ClockTime -> CalendarTime > toClockTime :: CalendarTime -> ClockTime
This proposal does not generally distinguish operations in this way, though definitions in terms of other operations are given where possible in order to simplify the semantics, aid comprehension, and speed implementation.
The following operations are currently defined in terms of other operations, and could therefore be considered "derived" in the sense used above. For the sake of completeness, the relevant definitions are repeated here.
> (>>) :: IO a -> IO b -> IO b > p >> q = p >>= const q > accumulate :: [IO a] -> IO [a] > accumulate = > foldr mcons (return []) > where > mcons :: IO a -> IO [a] -> IO [a] > mcons p q = p >>= \x -> q >>= \y -> return (x : y) > appendFile :: FilePath -> String -> IO () > appendFile name str = > openFile AppendMode name >>= \hdl -> hPutStr hdl str >> close hdl > either :: (a -> c) -> (b -> c) -> (Either a b) -> c > either f g (Left x) = f x > either f g (Right x) = g x > fail :: String -> IO a > fail = failwith . UserError > getChar :: IO Char > getChar = hGetChar stdin > hPutStr :: Handle -> String -> IO () > hPutText :: Text a => Handle -> a -> IO () > hPutStr hdl = foldr (>>) (return ()) . map (hPutChar hdl) > hPutText hdl = hPutStr hdl . show > interact :: (String -> String) -> IO () > interact f = hGetContents stdin >>= (putStr . f) > isEOF :: IO Bool > isEOF = hIsEOF stdin > print :: Text a => a -> IO () > print x = putText x >> putChar '\n' > putChar :: Char -> IO () > putStr :: String -> IO () > putText :: Text a => a -> IO () > putChar = hPutChar stdout > putStr = hPutStr stdout > putText = hPutText stdout > readFile :: FilePath -> IO String > readFile name = openFile ReadMode name >>= hGetContents > sequence :: [IO a] -> IO () > sequence = foldr (>>) (return ()) > try :: IO a -> IO (Either IOError a) > try p = handle (p >>= (return . Right)) Left > writeFile :: FilePath -> String -> IO () > writeFile name str = > openFile WriteMode name >>= \hdl -> hPutStr hdl str >> close hdl