foundation-0.0.3: Alternative prelude with batteries and no dependencies

License | BSD-style
Maintainer | Vincent Hanquez <vincent@snarc.org>
Stability | experimental
Portability | portable
Safe Haskell | None
Language | Haskell2010

Foundation.IO

Contents

- Terminal
- File

Description

IO Routine

Synopsis

- putStrLn :: String -> IO ()
- putStr :: String -> IO ()
- data IOMode :: *
  - = ReadMode
  - | WriteMode
  - | AppendMode
  - | ReadWriteMode
- openFile :: FilePath -> IOMode -> IO Handle
- closeFile :: Handle -> IO ()
- withFile :: FilePath -> IOMode -> (Handle -> IO r) -> IO r
- hGet :: Handle -> Int -> IO (UArray Word8)
- readFile :: FilePath -> IO (UArray Word8)
- foldTextFile :: (String -> a -> IO a) -> a -> FilePath -> IO a

# Terminal

putStrLn :: String -> IO () #

Print a string with a newline to standard output

putStr :: String -> IO () #

Print a string to standard output

# File

data IOMode :: * #

See `openFile`

Constructors

ReadMode |
WriteMode |
AppendMode |
ReadWriteMode |

Instances

Enum IOMode |
Methods succ :: IOMode -> IOMode # pred :: IOMode -> IOMode # toEnum :: Int -> IOMode # fromEnum :: IOMode -> Int # enumFrom :: IOMode -> [IOMode] # enumFromThen :: IOMode -> IOMode -> [IOMode] # enumFromTo :: IOMode -> IOMode -> [IOMode] # enumFromThenTo :: IOMode -> IOMode -> IOMode -> [IOMode] #
Eq IOMode |
Methods (==) :: IOMode -> IOMode -> Bool # (/=) :: IOMode -> IOMode -> Bool #
Ord IOMode |
Methods compare :: IOMode -> IOMode -> Ordering # (<) :: IOMode -> IOMode -> Bool # (<=) :: IOMode -> IOMode -> Bool # (>) :: IOMode -> IOMode -> Bool # (>=) :: IOMode -> IOMode -> Bool # max :: IOMode -> IOMode -> IOMode # min :: IOMode -> IOMode -> IOMode #
Read IOMode |
Methods readsPrec :: Int -> ReadS IOMode # readList :: ReadS [IOMode] # readPrec :: ReadPrec IOMode # readListPrec :: ReadPrec [IOMode] #
Show IOMode |
Methods showsPrec :: Int -> IOMode -> ShowS # show :: IOMode -> String # showList :: [IOMode] -> ShowS #
Ix IOMode |
Methods range :: (IOMode, IOMode) -> [IOMode] # index :: (IOMode, IOMode) -> IOMode -> Int # unsafeIndex :: (IOMode, IOMode) -> IOMode -> Int inRange :: (IOMode, IOMode) -> IOMode -> Bool # rangeSize :: (IOMode, IOMode) -> Int # unsafeRangeSize :: (IOMode, IOMode) -> Int

openFile :: FilePath -> IOMode -> IO Handle #

list the file name in the given FilePath directory

TODO: error management and not implemented yet getDirectory :: FilePath -> IO [FileName] getDirectory = undefined

Open a new handle on the file

closeFile :: Handle -> IO () #

Close a handle

withFile :: FilePath -> IOMode -> (Handle -> IO r) -> IO r #

``withFile` filepath mode act` opens a file using the mode`and run act`. the by-product handle will be closed when act finish, either normally or through an exception.

The value returned is the result of act@

hGet :: Handle -> Int -> IO (UArray Word8) #

Read binary data directly from the specified `Handle`.

First argument is the Handle to read from, and the second is the number of bytes to read. It returns the bytes read, up to the specified size, or an empty array if EOF has been reached.

`hGet` is implemented in terms of `hGetBuf`.

readFile :: FilePath -> IO (UArray Word8) #

Read a binary file and return the whole content in one contiguous buffer.

foldTextFile #

Arguments

:: (String -> a -> IO a) | Fold callback function
-> a | initial accumulator
-> FilePath | File to read
-> IO a |

Fold over chunks file calling the callback function for each chunks read from the file, until the end of file.