packages feed

explicit-iomodes 0.4.0.1 → 0.4.1

raw patch · 2 files changed

+136/−94 lines, 2 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ System.IO.ExplicitIOModes: class MkIOMode ioMode
+ System.IO.ExplicitIOModes: instance MkIOMode AppendMode
+ System.IO.ExplicitIOModes: instance MkIOMode ReadMode
+ System.IO.ExplicitIOModes: instance MkIOMode ReadWriteMode
+ System.IO.ExplicitIOModes: instance MkIOMode WriteMode
+ System.IO.ExplicitIOModes: mkIOMode :: (MkIOMode ioMode) => IOMode ioMode
+ System.IO.ExplicitIOModes: openBinaryFile' :: (MkIOMode ioMode) => FilePath -> IO (Handle ioMode)
+ System.IO.ExplicitIOModes: openFile' :: (MkIOMode ioMode) => FilePath -> IO (Handle ioMode)
+ System.IO.ExplicitIOModes: withBinaryFile' :: (MkIOMode ioMode) => FilePath -> (Handle ioMode -> IO α) -> IO α
+ System.IO.ExplicitIOModes: withFile' :: (MkIOMode ioMode) => FilePath -> (Handle ioMode -> IO α) -> IO α
- System.IO.ExplicitIOModes: withBinaryFile :: FilePath -> IOMode ioMode -> (Handle ioMode -> IO r) -> IO r
+ System.IO.ExplicitIOModes: withBinaryFile :: FilePath -> IOMode ioMode -> (Handle ioMode -> IO α) -> IO α

Files

System/IO/ExplicitIOModes.hs view
@@ -42,9 +42,6 @@       -- ** IO Modes        -- | Types that represent the IOMode a 'Handle' can be in.-    , IOMode(..)-    , regularIOMode-     , ReadMode     , WriteMode     , AppendMode@@ -53,6 +50,10 @@     , ReadModes     , WriteModes +    , IOMode(..)+    , MkIOMode(mkIOMode)+    , regularIOMode+       -- ** Standard handles        -- | These standard handles have concrete IOModes by default which work@@ -67,9 +68,13 @@        -- * Opening and closing files       -- ** Opening files-    , withFile     , openFile+    , withFile +      -- *** Opening files by inferring the IOMode+    , openFile'+    , withFile'+       -- ** Closing files     , hClose @@ -165,8 +170,14 @@     , SIO.readLn      -- * Binary input and output-    , withBinaryFile     , openBinaryFile+    , withBinaryFile++      -- ** Opening binary files by inferring the IOMode+    , openBinaryFile'+    , withBinaryFile'++      -- ** Operations on binary handles     , hSetBinaryMode     , hPutBuf     , hGetBuf@@ -249,17 +260,51 @@  -- ** IO Modes +-- | Read only.+data ReadMode++-- | Write only.+data WriteMode++-- | Write only by appending.+data AppendMode++-- | Both read and write.+data ReadWriteMode++-- | Class of readable IO mode types.+class ReadModes  ioMode++-- | Class of writable IO mode types.+class WriteModes ioMode++instance ReadModes ReadMode+instance ReadModes ReadWriteMode++instance WriteModes WriteMode+instance WriteModes AppendMode+instance WriteModes ReadWriteMode+ -- | The IOMode GADT which for each constructor specifies the associated IOMode -- type. ----- Also see: @System.IO.@'SIO.IOMode'.+-- Also see: @System.IO.'SIO.IOMode'@. data IOMode ioMode where     ReadMode      ∷ IOMode ReadMode     WriteMode     ∷ IOMode WriteMode     AppendMode    ∷ IOMode AppendMode     ReadWriteMode ∷ IOMode ReadWriteMode --- | Retrieves the regular @System.IO.@'SIO.IOMode'.+class MkIOMode ioMode where+    -- | An overloaded IOMode constructor.+    mkIOMode ∷ IOMode ioMode++instance MkIOMode ReadMode      where mkIOMode = ReadMode+instance MkIOMode WriteMode     where mkIOMode = WriteMode+instance MkIOMode AppendMode    where mkIOMode = AppendMode+instance MkIOMode ReadWriteMode where mkIOMode = ReadWriteMode++-- | Retrieves the regular @System.IO.'SIO.IOMode'@. regularIOMode ∷ IOMode ioMode → SIO.IOMode regularIOMode ReadMode      = SIO.ReadMode regularIOMode WriteMode     = SIO.WriteMode@@ -297,42 +342,18 @@     show AppendMode    = "AppendMode"     show ReadWriteMode = "ReadWriteMode" --- | Read only.-data ReadMode --- | Write only.-data WriteMode---- | Write only by appending.-data AppendMode---- | Both read and write.-data ReadWriteMode---- | Class of readable IO mode types.-class ReadModes  ioMode---- | Class of writable IO mode types.-class WriteModes ioMode--instance ReadModes ReadMode-instance ReadModes ReadWriteMode--instance WriteModes WriteMode-instance WriteModes AppendMode-instance WriteModes ReadWriteMode- -- ** Standard handles --- | Wraps: @System.IO.@'SIO.stdin'.+-- | Wraps: @System.IO.'SIO.stdin'@. stdin ∷ Handle ReadMode stdin = Handle SIO.stdin --- | Wraps: @System.IO.@'SIO.stdout'.+-- | Wraps: @System.IO.'SIO.stdout'@. stdout ∷ Handle WriteMode stdout = Handle SIO.stdout --- | Wraps: @System.IO.@'SIO.stderr'.+-- | Wraps: @System.IO.'SIO.stderr'@. stderr ∷ Handle WriteMode stderr = Handle SIO.stderr @@ -348,18 +369,12 @@ class CheckMode ioMode where     checkMode ∷ Tagged ioMode (SIO.Handle → IO Bool) -instance CheckMode ReadMode where-    checkMode = Tagged SIO.hIsReadable--instance CheckMode WriteMode where-    checkMode = Tagged SIO.hIsWritable--instance CheckMode AppendMode where-    checkMode = Tagged SIO.hIsWritable--instance CheckMode ReadWriteMode where-    checkMode = Tagged $ \h → liftM2 (∧) (SIO.hIsReadable h)-                                         (SIO.hIsWritable h)+instance CheckMode ReadMode      where checkMode = Tagged SIO.hIsReadable+instance CheckMode WriteMode     where checkMode = Tagged SIO.hIsWritable+instance CheckMode AppendMode    where checkMode = Tagged SIO.hIsWritable+instance CheckMode ReadWriteMode where checkMode = Tagged $+                                         \h → liftM2 (∧) (SIO.hIsReadable h)+                                                         (SIO.hIsWritable h)   --------------------------------------------------------------------------------@@ -368,17 +383,30 @@  -- ** Opening files --- | Wraps: @System.IO.@'SIO.withFile'.+-- | Wraps: @System.IO.'SIO.openFile'@.+openFile ∷ FilePath → IOMode ioMode → IO (Handle ioMode)+openFile fp = liftM Handle ∘ SIO.openFile fp ∘ regularIOMode++-- | Wraps: @System.IO.'SIO.withFile'@. withFile ∷ FilePath → IOMode ioMode → (Handle ioMode → IO α) → IO α withFile fp ioMode f = SIO.withFile fp (regularIOMode ioMode) $ f ∘ Handle --- | Wraps: @System.IO.@'SIO.openFile'.-openFile ∷ FilePath → IOMode ioMode → IO (Handle ioMode)-openFile fp = liftM Handle ∘ SIO.openFile fp ∘ regularIOMode+-- *** Opening files by inferring the IOMode +-- | Open a file without explicitly specifying the IOMode. The IOMode is+-- inferred from the type of the resulting 'Handle'.+--+-- Note that: @openFile' fp = 'openFile' fp 'mkIOMode'@.+openFile' ∷ MkIOMode ioMode ⇒ FilePath → IO (Handle ioMode)+openFile' fp = openFile fp mkIOMode++-- | Note that: @withFile' fp = 'withFile' fp 'mkIOMode'@.+withFile' ∷ MkIOMode ioMode ⇒ FilePath → (Handle ioMode → IO α) → IO α+withFile' fp = withFile fp mkIOMode+ -- ** Closing files --- | Wraps: @System.IO.@'SIO.hClose'.+-- | Wraps: @System.IO.'SIO.hClose'@. hClose ∷ Handle ioMode → IO () hClose = wrap SIO.hClose @@ -389,73 +417,73 @@  -- ** Determining and changing the size of a file --- | Wraps: @System.IO.@'SIO.hFileSize'.+-- | Wraps: @System.IO.'SIO.hFileSize'@. hFileSize ∷ Handle ioMode → IO Integer hFileSize = wrap SIO.hFileSize  #ifdef __GLASGOW_HASKELL__--- | Wraps: @System.IO.@'SIO.hSetFileSize'.+-- | Wraps: @System.IO.'SIO.hSetFileSize'@. hSetFileSize ∷ Handle ioMode → Integer → IO () hSetFileSize = wrap SIO.hSetFileSize #endif  -- ** Detecting the end of input --- | Wraps: @System.IO.@'SIO.hIsEOF'.+-- | Wraps: @System.IO.'SIO.hIsEOF'@. hIsEOF ∷ ReadModes ioMode ⇒ Handle ioMode → IO Bool hIsEOF = wrap SIO.hIsEOF   -- ** Buffering operations --- | Wraps: @System.IO.@'SIO.hSetBuffering'.+-- | Wraps: @System.IO.'SIO.hSetBuffering'@. hSetBuffering ∷ Handle ioMode → SIO.BufferMode → IO () hSetBuffering = wrap SIO.hSetBuffering --- | Wraps: @System.IO.@'SIO.hGetBuffering'.+-- | Wraps: @System.IO.'SIO.hGetBuffering'@. hGetBuffering ∷ Handle ioMode → IO SIO.BufferMode hGetBuffering = wrap SIO.hGetBuffering --- | Wraps: @System.IO.@'SIO.hFlush'.+-- | Wraps: @System.IO.'SIO.hFlush'@. hFlush ∷ Handle ioMode → IO () hFlush = wrap SIO.hFlush   -- ** Repositioning handles --- | Wraps: @System.IO.@'SIO.hGetPosn'.+-- | Wraps: @System.IO.'SIO.hGetPosn'@. hGetPosn ∷ Handle ioMode → IO SIO.HandlePosn hGetPosn = wrap SIO.hGetPosn --- | Wraps: @System.IO.@'SIO.hSeek'.+-- | Wraps: @System.IO.'SIO.hSeek'@. hSeek ∷ Handle ioMode → SIO.SeekMode → Integer → IO () hSeek = wrap SIO.hSeek  #if !defined(__NHC__)--- | Wraps: @System.IO.@'SIO.hTell'.+-- | Wraps: @System.IO.'SIO.hTell'@. hTell ∷ Handle ioMode → IO Integer hTell = wrap SIO.hTell #endif  -- ** Handle properties --- | Wraps: @System.IO.@'SIO.hIsOpen'.+-- | Wraps: @System.IO.'SIO.hIsOpen'@. hIsOpen ∷ Handle ioMode → IO Bool hIsOpen = wrap SIO.hIsOpen --- | Wraps: @System.IO.@'SIO.hIsClosed'.+-- | Wraps: @System.IO.'SIO.hIsClosed'@. hIsClosed ∷ Handle ioMode → IO Bool hIsClosed = wrap SIO.hIsClosed --- | Wraps: @System.IO.@'SIO.hIsReadable'.+-- | Wraps: @System.IO.'SIO.hIsReadable'@. hIsReadable ∷ Handle ioMode → IO Bool hIsReadable = wrap SIO.hIsReadable --- | Wraps: @System.IO.@'SIO.hIsWritable'.+-- | Wraps: @System.IO.'SIO.hIsWritable'@. hIsWritable ∷ Handle ioMode → IO Bool hIsWritable = wrap SIO.hIsWritable --- | Wraps: @System.IO.@'SIO.hIsSeekable'.+-- | Wraps: @System.IO.'SIO.hIsSeekable'@. hIsSeekable ∷ Handle ioMode → IO Bool hIsSeekable = wrap SIO.hIsSeekable @@ -463,15 +491,15 @@ -- ** Terminal operations (not portable: GHC/Hugs only)  #if !defined(__NHC__)--- | Wraps: @System.IO.@'SIO.hIsTerminalDevice'.+-- | Wraps: @System.IO.'SIO.hIsTerminalDevice'@. hIsTerminalDevice ∷ Handle ioMode → IO Bool hIsTerminalDevice = wrap SIO.hIsTerminalDevice --- | Wraps: @System.IO.@'SIO.hSetEcho'.+-- | Wraps: @System.IO.'SIO.hSetEcho'@. hSetEcho ∷ Handle ioMode → Bool → IO () hSetEcho = wrap SIO.hSetEcho --- | Wraps: @System.IO.@'SIO.hGetEcho'.+-- | Wraps: @System.IO.'SIO.hGetEcho'@. hGetEcho ∷ Handle ioMode → IO Bool hGetEcho = wrap SIO.hGetEcho #endif@@ -479,7 +507,7 @@ -- ** Showing handle state (not portable: GHC only)  #ifdef __GLASGOW_HASKELL__--- | Wraps: @System.IO.@'SIO.hShow'.+-- | Wraps: @System.IO.'SIO.hShow'@. hShow ∷ Handle ioMode → IO String hShow = wrap SIO.hShow #endif@@ -491,46 +519,46 @@  -- ** Text input --- | Wraps: @System.IO.@'SIO.hWaitForInput'.+-- | Wraps: @System.IO.'SIO.hWaitForInput'@. hWaitForInput ∷ ReadModes ioMode ⇒ Handle ioMode → Int → IO Bool hWaitForInput = wrap SIO.hWaitForInput --- | Wraps: @System.IO.@'SIO.hReady'.+-- | Wraps: @System.IO.'SIO.hReady'@. hReady ∷ ReadModes ioMode ⇒ Handle ioMode → IO Bool hReady = wrap SIO.hReady --- | Wraps: @System.IO.@'SIO.hGetChar'.+-- | Wraps: @System.IO.'SIO.hGetChar'@. hGetChar ∷ ReadModes ioMode ⇒ Handle ioMode → IO Char hGetChar = wrap SIO.hGetChar --- | Wraps: @System.IO.@'SIO.hGetLine'.+-- | Wraps: @System.IO.'SIO.hGetLine'@. hGetLine ∷ ReadModes ioMode ⇒ Handle ioMode → IO String hGetLine = wrap SIO.hGetLine --- | Wraps: @System.IO.@'SIO.hLookAhead'.+-- | Wraps: @System.IO.'SIO.hLookAhead'@. hLookAhead ∷ ReadModes ioMode ⇒ Handle ioMode → IO Char hLookAhead = wrap SIO.hLookAhead --- | Wraps: @System.IO.@'SIO.hGetContents'.+-- | Wraps: @System.IO.'SIO.hGetContents'@. hGetContents ∷ ReadModes ioMode ⇒ Handle ioMode → IO String hGetContents = wrap SIO.hGetContents   -- ** Text ouput --- | Wraps: @System.IO.@'SIO.hPutChar'.+-- | Wraps: @System.IO.'SIO.hPutChar'@. hPutChar ∷ WriteModes ioMode ⇒ Handle ioMode → Char → IO () hPutChar = wrap SIO.hPutChar --- | Wraps: @System.IO.@'SIO.hPutStr'.+-- | Wraps: @System.IO.'SIO.hPutStr'@. hPutStr ∷ WriteModes ioMode ⇒ Handle ioMode → String → IO () hPutStr = wrap SIO.hPutStr --- | Wraps: @System.IO.@'SIO.hPutStrLn'.+-- | Wraps: @System.IO.'SIO.hPutStrLn'@. hPutStrLn ∷ WriteModes ioMode ⇒ Handle ioMode → String → IO () hPutStrLn = wrap SIO.hPutStrLn --- | Wraps: @System.IO.@'SIO.hPrint'.+-- | Wraps: @System.IO.'SIO.hPrint'@. hPrint ∷ (WriteModes ioMode, Show α) ⇒ Handle ioMode → α → IO () hPrint = wrap SIO.hPrint @@ -539,32 +567,46 @@ -- * Binary input and output -------------------------------------------------------------------------------- --- | Wraps: @System.IO.@'SIO.withBinaryFile'.-withBinaryFile ∷ FilePath → IOMode ioMode → (Handle ioMode → IO r) → IO r-withBinaryFile fp ioMode f = SIO.withBinaryFile fp (regularIOMode ioMode) $ f ∘ Handle---- | Wraps: @System.IO.@'SIO.openBinaryFile'.+-- | Wraps: @System.IO.'SIO.openBinaryFile'@. openBinaryFile ∷ FilePath → IOMode ioMode → IO (Handle ioMode) openBinaryFile fp = liftM Handle ∘ SIO.openBinaryFile fp ∘ regularIOMode --- | Wraps: @System.IO.@'SIO.hSetBinaryMode'.+-- | Wraps: @System.IO.'SIO.withBinaryFile'@.+withBinaryFile ∷ FilePath → IOMode ioMode → (Handle ioMode → IO α) → IO α+withBinaryFile fp ioMode f = SIO.withBinaryFile fp (regularIOMode ioMode) $ f ∘ Handle+++-- ** Opening binary files by inferring the IOMode++-- | Note that: @openBinaryFile' fp = 'openBinaryFile' fp 'mkIOMode'@.+openBinaryFile' ∷ MkIOMode ioMode ⇒ FilePath → IO (Handle ioMode)+openBinaryFile' fp = openBinaryFile fp mkIOMode++-- | Note that: @withBinaryFile' fp = 'withBinaryFile' fp 'mkIOMode'@.+withBinaryFile' ∷ MkIOMode ioMode ⇒ FilePath → (Handle ioMode → IO α) → IO α+withBinaryFile' fp = withBinaryFile fp mkIOMode+++-- ** Operations on binary handles++-- | Wraps: @System.IO.'SIO.hSetBinaryMode'@. hSetBinaryMode ∷ Handle ioMode → Bool → IO () hSetBinaryMode = wrap SIO.hSetBinaryMode --- | Wraps: @System.IO.@'SIO.hPutBuf'.+-- | Wraps: @System.IO.'SIO.hPutBuf'@. hPutBuf ∷ WriteModes ioMode ⇒ Handle ioMode → Ptr α → Int → IO () hPutBuf = wrap SIO.hPutBuf --- | Wraps: @System.IO.@'SIO.hGetBuf'.+-- | Wraps: @System.IO.'SIO.hGetBuf'@. hGetBuf ∷ ReadModes ioMode ⇒ Handle ioMode → Ptr α → Int → IO Int hGetBuf = wrap SIO.hGetBuf  #if !defined(__NHC__) && !defined(__HUGS__)--- | Wraps: @System.IO.@'SIO.hPutBufNonBlocking'.+-- | Wraps: @System.IO.'SIO.hPutBufNonBlocking'@. hPutBufNonBlocking ∷ WriteModes ioMode ⇒ Handle ioMode → Ptr α → Int → IO Int hPutBufNonBlocking = wrap SIO.hPutBufNonBlocking --- | Wraps: @System.IO.@'SIO.hGetBufNonBlocking'.+-- | Wraps: @System.IO.'SIO.hGetBufNonBlocking'@. hGetBufNonBlocking ∷ ReadModes ioMode ⇒ Handle ioMode → Ptr α → Int → IO Int hGetBufNonBlocking = wrap SIO.hGetBufNonBlocking #endif@@ -574,12 +616,12 @@ -- * Temporary files -------------------------------------------------------------------------------- --- | Wraps: @System.IO.@'SIO.openTempFile'.+-- | Wraps: @System.IO.'SIO.openTempFile'@. openTempFile ∷ FilePath → String → IO (FilePath, Handle ReadWriteMode) openTempFile fp template =     liftM (second Handle) $ SIO.openTempFile fp template --- | Wraps: @System.IO.@'SIO.openBinaryTempFile'.+-- | Wraps: @System.IO.'SIO.openBinaryTempFile'@. openBinaryTempFile ∷ FilePath → String → IO (FilePath, Handle ReadWriteMode) openBinaryTempFile fp template =     liftM (second Handle) $ SIO.openBinaryTempFile fp template
explicit-iomodes.cabal view
@@ -1,5 +1,5 @@ name:          explicit-iomodes-version:       0.4.0.1+version:       0.4.1 cabal-version: >=1.6 build-type:    Simple license:       BSD3@@ -17,8 +17,8 @@                impossible to read from a write-only handle or write to                a read-only handle for example.                .-	       See the @explicit-iomodes-bytestring@ package for-	       @ByteString@ operations.+	       See the @explicit-iomodes-bytestring/text@ package for+	       @ByteString/Text@ operations.  source-repository head   Type:     darcs