foundation-0.0.30: Alternative prelude with batteries and no dependencies

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

Foundation.IO

Contents

- Terminal
- File

Description

IO Routine

Synopsis

- putStrLn :: String -> IO ()
- putStr :: String -> IO ()
- stdin :: Handle
- stdout :: Handle
- 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)
- hPut :: Handle -> UArray Word8 -> IO ()
- readFile :: FilePath -> IO (UArray Word8)

# Terminal

putStrLn :: String -> IO () Source #

Print a string with a newline to standard output

putStr :: String -> IO () Source #

Print a string to standard output

stdin :: Handle Source #

stdout :: Handle Source #

# File

data IOMode Source #

See `openFile`

Constructors

ReadMode |
WriteMode |
AppendMode |
ReadWriteMode |

#### Instances

Instances details

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

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

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 () Source #

Close a handle

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

``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) Source #

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`.

hPut :: Handle -> UArray Word8 -> IO () Source #

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

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