PreludeIO

The plain source file for module PreludeIO is not available.
module PreludeIO {-(
    FilePath, IOError(..), ioError, userError, catch,
    putChar, putStr, putStrLn, print,
    getChar, getLine, getContents, interact,
    readFile, writeFile, appendFile, readIO, readLn
  )-} where

import PreludeBuiltin

type  FilePath = String

data IOErrorKind
  = EOFError          
  | OtherError
  | UserError
  | AlreadyExistsError 
  | DoesNotExistError 
  | AlreadyInUseError 
  | FullError         
  | IllegalOperation  
  | PermissionError   
  deriving (Eq)
instance Eq IOErrorKind

-- The internals of this type are system dependent:
data IOError = IOE IOErrorKind String deriving (Eq)

instance  Show IOError  --where ...

instance  Eq IOError  --where ...

ioError          ::  IOError -> IO a
ioError          =   undefined--primIOError

userError        ::  String -> IOError
userError        =   undefined--primUserError

catch            ::  IO a -> (IOError -> IO a) -> IO a
catch            =   undefined--primCatch

putChar          :: Char -> IO ()
putChar          =  undefined--primPutChar

putStr           :: String -> IO ()
putStr s         =  mapM_ putChar s

putStrLn         :: String -> IO ()
putStrLn s       =  do putStr s
                       putStr "\n"

print            :: Show a => a -> IO ()
print x          =  putStrLn (show x)

getChar          :: IO Char
getChar          =  undefined--primGetChar

getLine          :: IO String
getLine          =  do c <- getChar
                       if c == '\n' then return "" else
                          do s <- getLine
                             return (c:s)


primitive getContents      :: IO String
primitive readFile         :: FilePath -> IO String
primitive writeFile        :: FilePath -> String -> IO ()
primitive appendFile       :: FilePath -> String -> IO ()

interact         ::  (String -> String) -> IO ()
interact f       =  do s <- getContents
                       putStr (f s)


  -- raises an exception instead of an error

readIO   :: Read a => String -> IO a
readIO s =  case [x | (x,t) <- reads s, ("","") <- lex t] of
              [x] -> return x
              []  -> ioError (userError "Prelude.readIO: no parse")
              _   -> ioError (userError "Prelude.readIO: ambiguous parse")

readLn           :: Read a => IO a
readLn           =  do l <- getLine
                       r <- readIO l
                       return r

Index

(HTML for this module was generated on Mar 20. About the conversion tool.)