ghc-internal-9.1201.0: Basic libraries
Copyright(c) The University of Glasgow 2017
Licensesee libraries/base/LICENSE
Maintainerlibraries@haskell.org
Stabilityinternal
Portabilitynon-portable
Safe HaskellTrustworthy
LanguageHaskell2010

GHC.Internal.IO.StdHandles

Description

This model abstracts away the platform specific handles that can be toggled through the RTS.

Synopsis

Documentation

stdin :: Handle Source #

stdin is a handle managing the programs standard input.

stdout :: Handle Source #

stdout is a handle managing the programs standard output.

stderr :: Handle Source #

stderr is a handle managing the programs standard error.

openFile Source #

Arguments

:: FilePath

The path to the file that should be opened

-> IOMode

The mode in which the file should be opened

-> IO Handle 

The computation openFile path mode returns a file handle that can be used to interact with the file.

The handle is open in text mode with localeEncoding. You can change the encoding with hSetEncoding.

openBinaryFile Source #

Arguments

:: FilePath

The path to the binary file that should be opened

-> IOMode

The mode in which the binary file should be opened

-> IO Handle 

The computation openBinaryFile path mode returns a file handle that can be used to interact with the binary file.

This is different from openFile as in that it does not use any file encoding.

withFile Source #

Arguments

:: FilePath

The path to the file that should be opened

-> IOMode

The mode in which the file should be opened

-> (Handle -> IO r)

The action to run with the obtained handle

-> IO r 

The computation withFile path mode action opens the file and runs action with the obtained handle before closing the file.

Even when an exception is raised within the action, the file will still be closed. This is why withFile path mode act is preferable to

openFile path mode >>= (\hdl -> act hdl >>= hClose hdl)

See also: bracket

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

The computation withBinaryFile path mode action opens the binary file and runs action with the obtained handle before closing the binary file.

This is different from withFile as in that it does not use any file encoding.

Even when an exception is raised within the action, the file will still be closed. This is why withBinaryFile path mode act is preferable to

openBinaryFile path mode >>= (\hdl -> act hdl >>= hClose hdl)

See also: bracket