Movatterモバイル変換
[0]ホーム
{-# LANGUAGE Trustworthy #-}{-# LANGUAGE CPP , NoImplicitPrelude , ExistentialQuantification #-}{-# OPTIONS_GHC -funbox-strict-fields #-}{-# OPTIONS_HADDOCK not-home #-}------------------------------------------------------------------------------- |-- Module : GHC.IO.Handle.Types-- Copyright : (c) The University of Glasgow, 1994-2009-- License : see libraries/base/LICENSE---- Maintainer : libraries@haskell.org-- Stability : internal-- Portability : non-portable---- Basic types for the implementation of IO Handles.-------------------------------------------------------------------------------moduleGHC.IO.Handle.Types(Handle(..),Handle__(..),showHandle,checkHandleInvariants,BufferList(..),HandleType(..),isReadableHandleType,isWritableHandleType,isReadWriteHandleType,isAppendHandleType,BufferMode(..),BufferCodec(..),NewlineMode(..),Newline(..),nativeNewline,universalNewlineMode,noNewlineTranslation,nativeNewlineMode)where#undef DEBUGimportGHC.BaseimportGHC.MVarimportGHC.IOimportGHC.IO.BufferimportGHC.IO.BufferedIOimportGHC.IO.Encoding.TypesimportGHC.IORefimportGHC.ShowimportGHC.ReadimportGHC.WordimportGHC.IO.DeviceimportData.Typeable#if defined(DEBUG)importControl.Monad#endif-- ----------------------------------------------------------------------------- Handle type-- A Handle is represented by (a reference to) a record-- containing the state of the I/O port/device. We record-- the following pieces of info:-- * type (read,write,closed etc.)-- * the underlying file descriptor-- * buffering mode-- * buffer, and spare buffers-- * user-friendly name (usually the-- FilePath used when IO.openFile was called)-- Note: when a Handle is garbage collected, we want to flush its buffer-- and close the OS file handle, so as to free up a (precious) resource.-- | Haskell defines operations to read and write characters from and to files,-- represented by values of type @Handle@. Each value of this type is a-- /handle/: a record used by the Haskell run-time system to /manage/ I\/O-- with file system objects. A handle has at least the following properties:---- * whether it manages input or output or both;---- * whether it is /open/, /closed/ or /semi-closed/;---- * whether the object is seekable;---- * whether buffering is disabled, or enabled on a line or block basis;---- * a buffer (whose length may be zero).---- Most handles will also have a current I\/O position indicating where the next-- input or output operation will occur. A handle is /readable/ if it-- manages only input or both input and output; likewise, it is /writable/ if-- it manages only output or both input and output. A handle is /open/ when-- first allocated.-- Once it is closed it can no longer be used for either input or output,-- though an implementation cannot re-use its storage while references-- remain to it. Handles are in the 'Show' and 'Eq' classes. The string-- produced by showing a handle is system dependent; it should include-- enough information to identify the handle for debugging. A handle is-- equal according to '==' only to itself; no attempt-- is made to compare the internal state of different handles for equality.dataHandle=FileHandle-- A normal handle to a fileFilePath-- the file (used for error messages-- only)!(MVarHandle__)|DuplexHandle-- A handle to a read/write streamFilePath-- file for a FIFO, otherwise some-- descriptive string (used for error-- messages only)!(MVarHandle__)-- The read side!(MVarHandle__)-- The write side-- NOTES:-- * A 'FileHandle' is seekable. A 'DuplexHandle' may or may not be-- seekable.-- | @since 4.1.0.0instanceEqHandlewhere(FileHandleFilePath_MVar Handle__h1)== :: Handle -> Handle -> Bool==(FileHandleFilePath_MVar Handle__h2)=MVar Handle__h1MVar Handle__ -> MVar Handle__ -> Boolforall a. Eq a => a -> a -> Bool==MVar Handle__h2(DuplexHandleFilePath_MVar Handle__h1MVar Handle___)==(DuplexHandleFilePath_MVar Handle__h2MVar Handle___)=MVar Handle__h1MVar Handle__ -> MVar Handle__ -> Boolforall a. Eq a => a -> a -> Bool==MVar Handle__h2Handle_==Handle_=BoolFalsedataHandle__=foralldevenc_statedec_state.(RawIOdev,IODevicedev,BufferedIOdev,Typeabledev)=>Handle__{()haDevice::!dev,Handle__ -> HandleTypehaType::HandleType,-- type (read/write/append etc.)Handle__ -> IORef (Buffer Word8)haByteBuffer::!(IORef(BufferWord8)),-- See Note [Buffering Implementation]Handle__ -> BufferModehaBufferMode::BufferMode,()haLastDecode::!(IORef(dec_state,BufferWord8)),-- ^ The byte buffer just before we did our last batch of decoding.Handle__ -> IORef (Buffer CharBufElem)haCharBuffer::!(IORef(BufferCharBufElem)),-- See Note [Buffering Implementation]Handle__ -> IORef (BufferList CharBufElem)haBuffers::!(IORef(BufferListCharBufElem)),-- spare buffers()haEncoder::Maybe(TextEncoderenc_state),()haDecoder::Maybe(TextDecoderdec_state),Handle__ -> Maybe TextEncodinghaCodec::MaybeTextEncoding,Handle__ -> NewlinehaInputNL::Newline,Handle__ -> NewlinehaOutputNL::Newline,Handle__ -> Maybe (MVar Handle__)haOtherSide::Maybe(MVarHandle__)-- ptr to the write side of a-- duplex handle.}-- we keep a few spare buffers around in a handle to avoid allocating-- a new one for each hPutStr. These buffers are *guaranteed* to be the-- same size as the main buffer.dataBufferListe=BufferListNil|BufferListCons(RawBuffere)(BufferListe)-- Internally, we classify handles as being one-- of the following:dataHandleType=ClosedHandle|SemiClosedHandle|ReadHandle|WriteHandle|AppendHandle|ReadWriteHandleisReadableHandleType::HandleType->BoolisReadableHandleType :: HandleType -> BoolisReadableHandleTypeHandleTypeReadHandle=BoolTrueisReadableHandleTypeHandleTypeReadWriteHandle=BoolTrueisReadableHandleTypeHandleType_=BoolFalseisWritableHandleType::HandleType->BoolisWritableHandleType :: HandleType -> BoolisWritableHandleTypeHandleTypeAppendHandle=BoolTrueisWritableHandleTypeHandleTypeWriteHandle=BoolTrueisWritableHandleTypeHandleTypeReadWriteHandle=BoolTrueisWritableHandleTypeHandleType_=BoolFalseisReadWriteHandleType::HandleType->BoolisReadWriteHandleType :: HandleType -> BoolisReadWriteHandleTypeReadWriteHandle{}=BoolTrueisReadWriteHandleTypeHandleType_=BoolFalseisAppendHandleType::HandleType->BoolisAppendHandleType :: HandleType -> BoolisAppendHandleTypeHandleTypeAppendHandle=BoolTrueisAppendHandleTypeHandleType_=BoolFalse-- INVARIANTS on Handles:---- * A handle *always* has a buffer, even if it is only 1 character long-- (an unbuffered handle needs a 1 character buffer in order to support-- hLookAhead and hIsEOF).-- * In a read Handle, the byte buffer is always empty (we decode when reading)-- * In a wriite Handle, the Char buffer is always empty (we encode when writing)--checkHandleInvariants::Handle__->IO()#if defined(DEBUG)checkHandleInvariantsh_=dobbuf<-readIORef(haByteBufferh_)checkBufferbbufcbuf<-readIORef(haCharBufferh_)checkBuffercbufwhen(isWriteBuffercbuf&¬(isEmptyBuffercbuf))$errorWithoutStackTrace("checkHandleInvariants: char write buffer non-empty: "++summaryBufferbbuf++", "++summaryBuffercbuf)when(isWriteBufferbbuf/=isWriteBuffercbuf)$errorWithoutStackTrace("checkHandleInvariants: buffer modes differ: "++summaryBufferbbuf++", "++summaryBuffercbuf)#elsecheckHandleInvariants :: Handle__ -> IO ()checkHandleInvariantsHandle___=() -> IO ()forall a. a -> IO aforall (m :: * -> *) a. Monad m => a -> m areturn()#endif-- ----------------------------------------------------------------------------- Buffering modes-- | Three kinds of buffering are supported: line-buffering,-- block-buffering or no-buffering. These modes have the following-- effects. For output, items are written out, or /flushed/,-- from the internal buffer according to the buffer mode:---- * /line-buffering/: the entire output buffer is flushed-- whenever a newline is output, the buffer overflows,-- a 'System.IO.hFlush' is issued, or the handle is closed.---- * /block-buffering/: the entire buffer is written out whenever it-- overflows, a 'System.IO.hFlush' is issued, or the handle is closed.---- * /no-buffering/: output is written immediately, and never stored-- in the buffer.---- An implementation is free to flush the buffer more frequently,-- but not less frequently, than specified above.-- The output buffer is emptied as soon as it has been written out.---- Similarly, input occurs according to the buffer mode for the handle:---- * /line-buffering/: when the buffer for the handle is not empty,-- the next item is obtained from the buffer; otherwise, when the-- buffer is empty, characters up to and including the next newline-- character are read into the buffer. No characters are available-- until the newline character is available or the buffer is full.---- * /block-buffering/: when the buffer for the handle becomes empty,-- the next block of data is read into the buffer.---- * /no-buffering/: the next input item is read and returned.-- The 'System.IO.hLookAhead' operation implies that even a no-buffered-- handle may require a one-character buffer.---- The default buffering mode when a handle is opened is-- implementation-dependent and may depend on the file system object-- which is attached to that handle.-- For most implementations, physical files will normally be block-buffered-- and terminals will normally be line-buffered.dataBufferMode=NoBuffering-- ^ buffering is disabled if possible.|LineBuffering-- ^ line-buffering should be enabled if possible.|BlockBuffering(MaybeInt)-- ^ block-buffering should be enabled if possible.-- The size of the buffer is @n@ items if the argument-- is 'Just' @n@ and is otherwise implementation-dependent.deriving(BufferMode -> BufferMode -> Bool(BufferMode -> BufferMode -> Bool)-> (BufferMode -> BufferMode -> Bool) -> Eq BufferModeforall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a$c== :: BufferMode -> BufferMode -> Bool== :: BufferMode -> BufferMode -> Bool$c/= :: BufferMode -> BufferMode -> Bool/= :: BufferMode -> BufferMode -> BoolEq-- ^ @since 4.2.0.0,Eq BufferModeEq BufferMode =>(BufferMode -> BufferMode -> Ordering)-> (BufferMode -> BufferMode -> Bool)-> (BufferMode -> BufferMode -> Bool)-> (BufferMode -> BufferMode -> Bool)-> (BufferMode -> BufferMode -> Bool)-> (BufferMode -> BufferMode -> BufferMode)-> (BufferMode -> BufferMode -> BufferMode)-> Ord BufferModeBufferMode -> BufferMode -> BoolBufferMode -> BufferMode -> OrderingBufferMode -> BufferMode -> BufferModeforall a.Eq a =>(a -> a -> Ordering)-> (a -> a -> Bool)-> (a -> a -> Bool)-> (a -> a -> Bool)-> (a -> a -> Bool)-> (a -> a -> a)-> (a -> a -> a)-> Ord a$ccompare :: BufferMode -> BufferMode -> Orderingcompare :: BufferMode -> BufferMode -> Ordering$c< :: BufferMode -> BufferMode -> Bool< :: BufferMode -> BufferMode -> Bool$c<= :: BufferMode -> BufferMode -> Bool<= :: BufferMode -> BufferMode -> Bool$c> :: BufferMode -> BufferMode -> Bool> :: BufferMode -> BufferMode -> Bool$c>= :: BufferMode -> BufferMode -> Bool>= :: BufferMode -> BufferMode -> Bool$cmax :: BufferMode -> BufferMode -> BufferModemax :: BufferMode -> BufferMode -> BufferMode$cmin :: BufferMode -> BufferMode -> BufferModemin :: BufferMode -> BufferMode -> BufferModeOrd-- ^ @since 4.2.0.0,ReadPrec [BufferMode]ReadPrec BufferModeInt -> ReadS BufferModeReadS [BufferMode](Int -> ReadS BufferMode)-> ReadS [BufferMode]-> ReadPrec BufferMode-> ReadPrec [BufferMode]-> Read BufferModeforall a.(Int -> ReadS a)-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a$creadsPrec :: Int -> ReadS BufferModereadsPrec :: Int -> ReadS BufferMode$creadList :: ReadS [BufferMode]readList :: ReadS [BufferMode]$creadPrec :: ReadPrec BufferModereadPrec :: ReadPrec BufferMode$creadListPrec :: ReadPrec [BufferMode]readListPrec :: ReadPrec [BufferMode]Read-- ^ @since 4.2.0.0,Int -> BufferMode -> ShowS[BufferMode] -> ShowSBufferMode -> FilePath(Int -> BufferMode -> ShowS)-> (BufferMode -> FilePath)-> ([BufferMode] -> ShowS)-> Show BufferModeforall a.(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a$cshowsPrec :: Int -> BufferMode -> ShowSshowsPrec :: Int -> BufferMode -> ShowS$cshow :: BufferMode -> FilePathshow :: BufferMode -> FilePath$cshowList :: [BufferMode] -> ShowSshowList :: [BufferMode] -> ShowSShow-- ^ @since 4.2.0.0){-Note [Buffering Implementation]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Each Handle has two buffers: a byte buffer (haByteBuffer) and a Charbuffer (haCharBuffer).Note [Buffered Reading]~~~~~~~~~~~~~~~~~~~~~~~For read Handles, bytes are read into the byte buffer, and immediatelydecoded into the Char buffer (seeGHC.IO.Handle.Internals.readTextDevice). The only way there might besome data left in the byte buffer is if there is a partial multi-bytecharacter sequence that cannot be decoded into a full character.Note that the buffering mode (haBufferMode) makes no difference whenreading data into a Handle. When reading, we can always just read allthe data there is available without blocking, decode it into the Charbuffer, and then provide it immediately to the caller.Note [Buffered Writing]~~~~~~~~~~~~~~~~~~~~~~~Characters are written into the Char buffer by e.g. hPutStr. At theend of the operation, or when the char buffer is full, the buffer isdecoded to the byte buffer (see writeCharBuffer). This is so that wecan detect encoding errors at the right point.Hence, the Char buffer is always empty between Handle operations.Note [Buffer Sizing]~~~~~~~~~~~~~~~~~~~~The char buffer is always a default size (dEFAULT_CHAR_BUFFER_SIZE).The byte buffer size is chosen by the underlying device (via itsIODevice.newBuffer). Hence the size of these buffers is not underuser control.There are certain minimum sizes for these buffers imposed by thelibrary (but not checked): - we must be able to buffer at least one character, so that hLookAhead can work - the byte buffer must be able to store at least one encoded character in the current encoding (6 bytes?) - when reading, the char buffer must have room for two characters, so that we can spot the \r\n sequence.How do we implement hSetBuffering?For reading, we have never used the user-supplied buffer size, becausethere's no point: we always pass all available data to the readerimmediately. Buffering would imply waiting until a certain amount ofdata is available, which has no advantages. So hSetBuffering isessentially a no-op for read handles, except that it turns on/off rawmode for the underlying device if necessary.For writing, the buffering mode is handled by the write operationsthemselves (hPutChar and hPutStr). Every write ends withwriteCharBuffer, which checks whether the buffer should be flushedaccording to the current buffering mode. Additionally, we look fornewlines and flush if the mode is LineBuffering.Note [Buffer Flushing]~~~~~~~~~~~~~~~~~~~~~~** Flushing the Char bufferWe must be able to flush the Char buffer, in order to implementhSetEncoding, and things like hGetBuf which want to read raw bytes.Flushing the Char buffer on a write Handle is easy: it is always empty.Flushing the Char buffer on a read Handle involves rewinding the bytebuffer to the point representing the next Char in the Char buffer.This is done by - remembering the state of the byte buffer *before* the last decode - re-decoding the bytes that represent the chars already read from the Char buffer. This gives us the point in the byte buffer that represents the *next* Char to be read.In order for this to work, after readTextHandle we must NOT MODIFY THECONTENTS OF THE BYTE OR CHAR BUFFERS, except to remove characters fromthe Char buffer.** Flushing the byte bufferThe byte buffer can be flushed if the Char buffer has already beenflushed (see above). For a read Handle, flushing the byte buffermeans seeking the device back by the number of bytes in the buffer,and hence it is only possible on a seekable Handle.-}-- ----------------------------------------------------------------------------- Newline translation-- | The representation of a newline in the external file or stream.dataNewline=LF-- ^ @\'\\n\'@|CRLF-- ^ @\'\\r\\n\'@deriving(Newline -> Newline -> Bool(Newline -> Newline -> Bool)-> (Newline -> Newline -> Bool) -> Eq Newlineforall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a$c== :: Newline -> Newline -> Bool== :: Newline -> Newline -> Bool$c/= :: Newline -> Newline -> Bool/= :: Newline -> Newline -> BoolEq-- ^ @since 4.2.0.0,Eq NewlineEq Newline =>(Newline -> Newline -> Ordering)-> (Newline -> Newline -> Bool)-> (Newline -> Newline -> Bool)-> (Newline -> Newline -> Bool)-> (Newline -> Newline -> Bool)-> (Newline -> Newline -> Newline)-> (Newline -> Newline -> Newline)-> Ord NewlineNewline -> Newline -> BoolNewline -> Newline -> OrderingNewline -> Newline -> Newlineforall a.Eq a =>(a -> a -> Ordering)-> (a -> a -> Bool)-> (a -> a -> Bool)-> (a -> a -> Bool)-> (a -> a -> Bool)-> (a -> a -> a)-> (a -> a -> a)-> Ord a$ccompare :: Newline -> Newline -> Orderingcompare :: Newline -> Newline -> Ordering$c< :: Newline -> Newline -> Bool< :: Newline -> Newline -> Bool$c<= :: Newline -> Newline -> Bool<= :: Newline -> Newline -> Bool$c> :: Newline -> Newline -> Bool> :: Newline -> Newline -> Bool$c>= :: Newline -> Newline -> Bool>= :: Newline -> Newline -> Bool$cmax :: Newline -> Newline -> Newlinemax :: Newline -> Newline -> Newline$cmin :: Newline -> Newline -> Newlinemin :: Newline -> Newline -> NewlineOrd-- ^ @since 4.3.0.0,ReadPrec [Newline]ReadPrec NewlineInt -> ReadS NewlineReadS [Newline](Int -> ReadS Newline)-> ReadS [Newline]-> ReadPrec Newline-> ReadPrec [Newline]-> Read Newlineforall a.(Int -> ReadS a)-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a$creadsPrec :: Int -> ReadS NewlinereadsPrec :: Int -> ReadS Newline$creadList :: ReadS [Newline]readList :: ReadS [Newline]$creadPrec :: ReadPrec NewlinereadPrec :: ReadPrec Newline$creadListPrec :: ReadPrec [Newline]readListPrec :: ReadPrec [Newline]Read-- ^ @since 4.3.0.0,Int -> Newline -> ShowS[Newline] -> ShowSNewline -> FilePath(Int -> Newline -> ShowS)-> (Newline -> FilePath) -> ([Newline] -> ShowS) -> Show Newlineforall a.(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a$cshowsPrec :: Int -> Newline -> ShowSshowsPrec :: Int -> Newline -> ShowS$cshow :: Newline -> FilePathshow :: Newline -> FilePath$cshowList :: [Newline] -> ShowSshowList :: [Newline] -> ShowSShow-- ^ @since 4.3.0.0)-- | Specifies the translation, if any, of newline characters between-- internal Strings and the external file or stream. Haskell Strings-- are assumed to represent newlines with the @\'\\n\'@ character; the-- newline mode specifies how to translate @\'\\n\'@ on output, and what to-- translate into @\'\\n\'@ on input.dataNewlineMode=NewlineMode{NewlineMode -> NewlineinputNL::Newline,-- ^ the representation of newlines on inputNewlineMode -> NewlineoutputNL::Newline-- ^ the representation of newlines on output}deriving(NewlineMode -> NewlineMode -> Bool(NewlineMode -> NewlineMode -> Bool)-> (NewlineMode -> NewlineMode -> Bool) -> Eq NewlineModeforall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a$c== :: NewlineMode -> NewlineMode -> Bool== :: NewlineMode -> NewlineMode -> Bool$c/= :: NewlineMode -> NewlineMode -> Bool/= :: NewlineMode -> NewlineMode -> BoolEq-- ^ @since 4.2.0.0,Eq NewlineModeEq NewlineMode =>(NewlineMode -> NewlineMode -> Ordering)-> (NewlineMode -> NewlineMode -> Bool)-> (NewlineMode -> NewlineMode -> Bool)-> (NewlineMode -> NewlineMode -> Bool)-> (NewlineMode -> NewlineMode -> Bool)-> (NewlineMode -> NewlineMode -> NewlineMode)-> (NewlineMode -> NewlineMode -> NewlineMode)-> Ord NewlineModeNewlineMode -> NewlineMode -> BoolNewlineMode -> NewlineMode -> OrderingNewlineMode -> NewlineMode -> NewlineModeforall a.Eq a =>(a -> a -> Ordering)-> (a -> a -> Bool)-> (a -> a -> Bool)-> (a -> a -> Bool)-> (a -> a -> Bool)-> (a -> a -> a)-> (a -> a -> a)-> Ord a$ccompare :: NewlineMode -> NewlineMode -> Orderingcompare :: NewlineMode -> NewlineMode -> Ordering$c< :: NewlineMode -> NewlineMode -> Bool< :: NewlineMode -> NewlineMode -> Bool$c<= :: NewlineMode -> NewlineMode -> Bool<= :: NewlineMode -> NewlineMode -> Bool$c> :: NewlineMode -> NewlineMode -> Bool> :: NewlineMode -> NewlineMode -> Bool$c>= :: NewlineMode -> NewlineMode -> Bool>= :: NewlineMode -> NewlineMode -> Bool$cmax :: NewlineMode -> NewlineMode -> NewlineModemax :: NewlineMode -> NewlineMode -> NewlineMode$cmin :: NewlineMode -> NewlineMode -> NewlineModemin :: NewlineMode -> NewlineMode -> NewlineModeOrd-- ^ @since 4.3.0.0,ReadPrec [NewlineMode]ReadPrec NewlineModeInt -> ReadS NewlineModeReadS [NewlineMode](Int -> ReadS NewlineMode)-> ReadS [NewlineMode]-> ReadPrec NewlineMode-> ReadPrec [NewlineMode]-> Read NewlineModeforall a.(Int -> ReadS a)-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a$creadsPrec :: Int -> ReadS NewlineModereadsPrec :: Int -> ReadS NewlineMode$creadList :: ReadS [NewlineMode]readList :: ReadS [NewlineMode]$creadPrec :: ReadPrec NewlineModereadPrec :: ReadPrec NewlineMode$creadListPrec :: ReadPrec [NewlineMode]readListPrec :: ReadPrec [NewlineMode]Read-- ^ @since 4.3.0.0,Int -> NewlineMode -> ShowS[NewlineMode] -> ShowSNewlineMode -> FilePath(Int -> NewlineMode -> ShowS)-> (NewlineMode -> FilePath)-> ([NewlineMode] -> ShowS)-> Show NewlineModeforall a.(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a$cshowsPrec :: Int -> NewlineMode -> ShowSshowsPrec :: Int -> NewlineMode -> ShowS$cshow :: NewlineMode -> FilePathshow :: NewlineMode -> FilePath$cshowList :: [NewlineMode] -> ShowSshowList :: [NewlineMode] -> ShowSShow-- ^ @since 4.3.0.0)-- | The native newline representation for the current platform: 'LF'-- on Unix systems, 'CRLF' on Windows.nativeNewline::Newline#if defined(mingw32_HOST_OS)nativeNewline=CRLF#elsenativeNewline :: NewlinenativeNewline=NewlineLF#endif-- | Map @\'\\r\\n\'@ into @\'\\n\'@ on input, and @\'\\n\'@ to the native newline-- representation on output. This mode can be used on any platform, and-- works with text files using any newline convention. The downside is-- that @readFile >>= writeFile@ might yield a different file.---- > universalNewlineMode = NewlineMode { inputNL = CRLF,-- > outputNL = nativeNewline }--universalNewlineMode::NewlineModeuniversalNewlineMode :: NewlineModeuniversalNewlineMode=NewlineMode{inputNL :: NewlineinputNL=NewlineCRLF,outputNL :: NewlineoutputNL=NewlinenativeNewline}-- | Use the native newline representation on both input and output---- > nativeNewlineMode = NewlineMode { inputNL = nativeNewline-- > outputNL = nativeNewline }--nativeNewlineMode::NewlineModenativeNewlineMode :: NewlineModenativeNewlineMode=NewlineMode{inputNL :: NewlineinputNL=NewlinenativeNewline,outputNL :: NewlineoutputNL=NewlinenativeNewline}-- | Do no newline translation at all.---- > noNewlineTranslation = NewlineMode { inputNL = LF, outputNL = LF }--noNewlineTranslation::NewlineModenoNewlineTranslation :: NewlineModenoNewlineTranslation=NewlineMode{inputNL :: NewlineinputNL=NewlineLF,outputNL :: NewlineoutputNL=NewlineLF}-- ----------------------------------------------------------------------------- Show instance for Handles-- handle types are 'show'n when printing error msgs, so-- we provide a more user-friendly Show instance for it-- than the derived one.-- | @since 4.1.0.0instanceShowHandleTypewhereshowsPrec :: Int -> HandleType -> ShowSshowsPrecInt_HandleTypet=caseHandleTypetofHandleTypeClosedHandle->FilePath -> ShowSshowStringFilePath"closed"HandleTypeSemiClosedHandle->FilePath -> ShowSshowStringFilePath"semi-closed"HandleTypeReadHandle->FilePath -> ShowSshowStringFilePath"readable"HandleTypeWriteHandle->FilePath -> ShowSshowStringFilePath"writable"HandleTypeAppendHandle->FilePath -> ShowSshowStringFilePath"writable (append)"HandleTypeReadWriteHandle->FilePath -> ShowSshowStringFilePath"read-writable"-- | @since 4.1.0.0instanceShowHandlewhereshowsPrec :: Int -> Handle -> ShowSshowsPrecInt_(FileHandleFilePathfileMVar Handle___)=FilePath -> ShowSshowHandleFilePathfileshowsPrecInt_(DuplexHandleFilePathfileMVar Handle___MVar Handle___)=FilePath -> ShowSshowHandleFilePathfileshowHandle::FilePath->String->StringshowHandle :: FilePath -> ShowSshowHandleFilePathfile=FilePath -> ShowSshowStringFilePath"{handle: "ShowS -> ShowS -> ShowSforall b c a. (b -> c) -> (a -> b) -> a -> c.FilePath -> ShowSshowStringFilePathfileShowS -> ShowS -> ShowSforall b c a. (b -> c) -> (a -> b) -> a -> c.FilePath -> ShowSshowStringFilePath"}"
[8]ページ先頭