Copyright | (c) Nicolas Pouillard 2009 |
---|---|
License | BSD3 |
Maintainer | Nicolas Pouillard <nicolas.pouillard@gmail.com> |
Stability | provisional |
Safe Haskell | None |
Language | Haskell98 |
- Types
- Functions stricter than there System.IO counterparts
- Functions as strict as there System.IO counterparts
This module wraps the functions of the System.IO module at a different type namely SIO
.
The purpose of this module is to export only strict IO functions, by strict
we mean strict in the result. The arguments of these functions may only by partially forced,
but when the function returns, the arguments can no longer be forced by the function.
When the type of the value to be forced is polymorphic, a NFData
constraint is added
since we (internally) use rnf
to force the value. Then we rely on the behavior
of NFData
instances to provide the fact that any lazy argument passed to a SIO
function
will not leak-out after the call.
These functions do not necessarily use their arguments completely but they do not hold
or return any value that could depend on these arguments. If the original functions
from System.IO module were already strict, then this module just provides them
at another type.
Some functions from the original module are famously lazy like the getContents
like
functions: in this module their results are deeply forced.
In Haskell, monad operations (return
and >>=
) have to be lazy. Therefore the SIO
monad is not completely strict (i.e. pure values can still be lazy). So in this module we
expose the return'
function that forces the given value before putting it into the monad.
Since this module uses the same names as System.IO, it is designed to be imported qualified.
import System.IO.Strict (SIO) import qualified System.IO.Strict as SIO
- data SIO a
- run :: NFData sa => SIO sa -> IO sa
- return' :: (Monad m, NFData sa) => sa -> m sa
- getContents :: SIO String
- hGetContents :: Handle -> SIO String
- readFile :: FilePath -> SIO String
- read :: (NFData sa, Read sa) => String -> SIO sa
- readLn :: (NFData sa, Read sa) => SIO sa
- fix :: NFData sa => (sa -> SIO sa) -> SIO sa
- withBinaryFile :: NFData sr => FilePath -> IOMode -> (Handle -> SIO sr) -> SIO sr
- withFile :: NFData sr => FilePath -> IOMode -> (Handle -> SIO sr) -> SIO sr
- appendFile :: FilePath -> String -> SIO ()
- getChar :: SIO Char
- getLine :: SIO String
- hPrint :: Show a => Handle -> a -> SIO ()
- hPutStrLn :: Handle -> String -> SIO ()
- hReady :: Handle -> SIO Bool
- interact :: (String -> String) -> SIO ()
- openBinaryTempFile :: FilePath -> String -> SIO (FilePath, Handle)
- openTempFile :: FilePath -> String -> SIO (FilePath, Handle)
- print :: Show a => a -> SIO ()
- putChar :: Char -> SIO ()
- putStr :: String -> SIO ()
- putStrLn :: String -> SIO ()
- writeFile :: FilePath -> String -> SIO ()
- hClose :: Handle -> SIO ()
- hFileSize :: Handle -> SIO Integer
- hFlush :: Handle -> SIO ()
- hGetBuf :: Handle -> Ptr a -> Int -> SIO Int
- hGetBufNonBlocking :: Handle -> Ptr a -> Int -> SIO Int
- hGetBuffering :: Handle -> SIO BufferMode
- hGetChar :: Handle -> SIO Char
- hGetEcho :: Handle -> SIO Bool
- hGetLine :: Handle -> SIO String
- hGetPosn :: Handle -> SIO HandlePosn
- hIsClosed :: Handle -> SIO Bool
- hIsEOF :: Handle -> SIO Bool
- hIsOpen :: Handle -> SIO Bool
- hIsReadable :: Handle -> SIO Bool
- hIsSeekable :: Handle -> SIO Bool
- hIsTerminalDevice :: Handle -> SIO Bool
- hIsWritable :: Handle -> SIO Bool
- hLookAhead :: Handle -> SIO Char
- hPutBuf :: Handle -> Ptr a -> Int -> SIO ()
- hPutBufNonBlocking :: Handle -> Ptr a -> Int -> SIO Int
- hPutChar :: Handle -> Char -> SIO ()
- hPutStr :: Handle -> String -> SIO ()
- hSeek :: Handle -> SeekMode -> Integer -> SIO ()
- hSetBinaryMode :: Handle -> Bool -> SIO ()
- hSetBuffering :: Handle -> BufferMode -> SIO ()
- hSetEcho :: Handle -> Bool -> SIO ()
- hSetFileSize :: Handle -> Integer -> SIO ()
- hSetPosn :: HandlePosn -> SIO ()
- hShow :: Handle -> SIO String
- hTell :: Handle -> SIO Integer
- hWaitForInput :: Handle -> Int -> SIO Bool
- isEOF :: SIO Bool
- openBinaryFile :: FilePath -> IOMode -> SIO Handle
- openFile :: FilePath -> IOMode -> SIO Handle
- stderr :: Handle
- stdin :: Handle
- stdout :: Handle
Types
return' :: (Monad m, NFData sa) => sa -> m sa Source #
A stricter version of return
, that works for every monad.
Functions stricter than there System.IO counterparts
getContents :: SIO String Source #
Note that getContents
is stricter than its counterpart in System.IO.
hGetContents :: Handle -> SIO String Source #
Note that hGetContents
is stricter than its counterpart in System.IO.
withBinaryFile :: NFData sr => FilePath -> IOMode -> (Handle -> SIO sr) -> SIO sr Source #
Note that withBinaryFile
is stricter than its counterpart in System.IO.
Functions as strict as there System.IO counterparts
hGetBuffering :: Handle -> SIO BufferMode Source #
hSetBuffering :: Handle -> BufferMode -> SIO () Source #
hSetPosn :: HandlePosn -> SIO () Source #