packages feed

safer-file-handles 0.8 → 0.9

raw patch · 3 files changed

+122/−73 lines, 3 filesdep +monad-peeldep −MonadCatchIO-transformersdep ~basedep ~explicit-iomodesdep ~regional-pointers

Dependencies added: monad-peel

Dependencies removed: MonadCatchIO-transformers

Dependency ranges changed: base, explicit-iomodes, regional-pointers, regions

Files

System/IO/SaferFileHandles.hs view
@@ -72,6 +72,14 @@       {-| These standard handles have concrete IOModes by default which work       for the majority of cases. In the rare occasion that you know these       handles have different IOModes you can 'cast' them.++      Note that these handles a pure values. This means they don't perform the+      side-effect of registering a finalizer like @hClose stdin@ in the+      'RegionT' monad.++      Finally note that the region parameter of the handles is set to+      'RootRegion' which is the ancestor of any region. This allows the standard+      handles to be used in any region.       -}     , stdin, stdout, stderr     , cast@@ -185,6 +193,9 @@     , hGetBuf  #if !defined(__NHC__) && !defined(__HUGS__)+#if MIN_VERSION_base(4,3,0)+    , hGetBufSome+#endif     , hPutBufNonBlocking     , hGetBufNonBlocking #endif@@ -231,7 +242,7 @@  -- from base: import Prelude           ( Integer )-import Control.Monad     ( return, (>>=), fail, liftM )+import Control.Monad     ( return, (>>=), liftM ) import Data.Bool         ( Bool(..) ) import Data.Function     ( ($), flip ) import Data.Functor      ( fmap )@@ -244,6 +255,10 @@  import qualified System.IO as SIO +#if __GLASGOW_HASKELL__ < 701+import Control.Monad     ( fail )+#endif+ #ifdef __HADDOCK__ import System.IO.Error #endif@@ -251,8 +266,9 @@ -- from base-unicode-symbols: import Data.Function.Unicode ( (∘) ) --- from MonadCatchIO-transformers:-import Control.Monad.CatchIO ( MonadCatchIO, block )+-- from monad-peel:+import Control.Monad.IO.Peel  ( MonadPeelIO )+import Control.Exception.Peel ( block )  -- from transformers: import Control.Monad.IO.Class ( MonadIO, liftIO )@@ -327,15 +343,15 @@ -------------------------------------------------------------------------------  -- | Wraps: @System.IO.'SIO.stdin'@.-stdin ∷ RegionalFileHandle ReadMode r+stdin ∷ RegionalFileHandle ReadMode RootRegion stdin = RegionalFileHandle E.stdin Nothing  -- | Wraps: @System.IO.'SIO.stdout'@.-stdout ∷ RegionalFileHandle WriteMode r+stdout ∷ RegionalFileHandle WriteMode RootRegion stdout = RegionalFileHandle E.stdout Nothing  -- | Wraps: @System.IO.'SIO.stderr'@.-stderr ∷ RegionalFileHandle WriteMode r+stderr ∷ RegionalFileHandle WriteMode RootRegion stderr = RegionalFileHandle E.stderr Nothing  {-| Cast the IOMode of a handle if the handle supports it.@@ -344,7 +360,7 @@ you know the IOMode of a handle is different from its default IOMode you can cast it to the right one. -}-cast ∷ (pr `ParentOf` cr, MonadIO cr, CheckMode castedIOMode)+cast ∷ (pr `AncestorRegion` cr, MonadIO cr, CheckMode castedIOMode)      ⇒ RegionalFileHandle anyIOMode pr      → cr (Maybe (RegionalFileHandle castedIOMode pr)) cast (RegionalFileHandle h mbCloseHndl) =@@ -393,14 +409,14 @@ Note: if you will be working with files containing binary data, you'll want to be using 'openBinaryFile'. -}-openFile ∷ (MonadCatchIO pr, AbsRelClass ar)+openFile ∷ (MonadPeelIO pr, AbsRelClass ar)          ⇒ FilePath ar          → IOMode ioMode          → RegionT s pr              (RegionalFileHandle ioMode (RegionT s pr)) openFile = openNormal E.openFile -openNormal ∷ (MonadCatchIO pr, AbsRelClass ar)+openNormal ∷ (MonadPeelIO pr, AbsRelClass ar)            ⇒ (E.FilePath → IOMode ioMode → IO (E.Handle ioMode))            → ( FilePath ar              → IOMode ioMode@@ -416,7 +432,7 @@ function to the resulting regional file handle and runs the resulting region. This provides a safer safer replacement for @System.IO.'SIO.withFile'@. -}-withFile ∷ (MonadCatchIO pr, AbsRelClass ar)+withFile ∷ (MonadPeelIO pr, AbsRelClass ar)          ⇒ FilePath ar          → IOMode ioMode          → (∀ s. RegionalFileHandle ioMode (RegionT s pr) → RegionT s pr α)@@ -429,14 +445,14 @@ -- inferred from the type of the resulting 'RegionalFileHandle'. -- -- Note that: @openFile' fp = 'openFile' fp 'mkIOMode'@.-openFile' ∷ (MonadCatchIO pr, AbsRelClass ar, MkIOMode ioMode)+openFile' ∷ (MonadPeelIO pr, AbsRelClass ar, MkIOMode ioMode)           ⇒ FilePath ar           → RegionT s pr               (RegionalFileHandle ioMode (RegionT s pr)) openFile' filePath = openFile filePath mkIOMode  -- | Note that: @withFile' filePath = 'withFile' filePath 'mkIOMode'@.-withFile' ∷ (MonadCatchIO pr, AbsRelClass ar, MkIOMode ioMode)+withFile' ∷ (MonadPeelIO pr, AbsRelClass ar, MkIOMode ioMode)           ⇒ FilePath ar           → (∀ s. RegionalFileHandle ioMode (RegionT s pr) → RegionT s pr α)           → pr α@@ -453,7 +469,7 @@ -- 'hFileSize' @hdl@ returns the size of that file in 8-bit bytes. -- -- Wraps: @System.IO.'SIO.hFileSize'@.-hFileSize ∷ (pr `ParentOf` cr, MonadIO cr)+hFileSize ∷ (pr `AncestorRegion` cr, MonadIO cr)           ⇒ RegionalFileHandle ioMode pr → cr Integer hFileSize = wrap E.hFileSize @@ -462,7 +478,7 @@ -- to @size@ bytes. -- -- Wraps: @System.IO.'SIO.hSetFileSize'@.-hSetFileSize ∷ (pr `ParentOf` cr, MonadIO cr)+hSetFileSize ∷ (pr `AncestorRegion` cr, MonadIO cr)              ⇒ RegionalFileHandle ioMode pr → Integer → cr () hSetFileSize = wrap2 E.hSetFileSize #endif@@ -479,7 +495,7 @@ -- 'hLookAhead' and checking for an EOF exception. -- -- Wraps: @System.IO.'SIO.hIsEOF'@.-hIsEOF ∷ (pr `ParentOf` cr, MonadIO cr, ReadModes ioMode)+hIsEOF ∷ (pr `AncestorRegion` cr, MonadIO cr, ReadModes ioMode)        ⇒ RegionalFileHandle ioMode pr → cr Bool hIsEOF = wrap E.hIsEOF @@ -507,7 +523,7 @@ --    to be changed. -- -- Wraps: @System.IO.'SIO.hSetBuffering'@.-hSetBuffering ∷ (pr `ParentOf` cr, MonadIO cr)+hSetBuffering ∷ (pr `AncestorRegion` cr, MonadIO cr)               ⇒ RegionalFileHandle ioMode pr → BufferMode → cr () hSetBuffering = wrap2 E.hSetBuffering @@ -515,7 +531,7 @@ -- @hdl@. -- -- Wraps: @System.IO.'SIO.hGetBuffering'@.-hGetBuffering ∷ (pr `ParentOf` cr, MonadIO cr)+hGetBuffering ∷ (pr `AncestorRegion` cr, MonadIO cr)               ⇒ RegionalFileHandle ioMode pr → cr BufferMode hGetBuffering = wrap E.hGetBuffering @@ -531,7 +547,7 @@ --  under these circumstances. -- -- Wraps: @System.IO.'SIO.hFlush'@.-hFlush ∷ (pr `ParentOf` cr, MonadIO cr, WriteModes ioMode)+hFlush ∷ (pr `AncestorRegion` cr, MonadIO cr, WriteModes ioMode)        ⇒ RegionalFileHandle ioMode pr → cr () hFlush = wrap E.hFlush @@ -542,7 +558,7 @@ -- a value of the abstract type 'HandlePosn'. -- -- Wraps: @System.IO.'SIO.hGetPosn'@.-hGetPosn ∷ (pr `ParentOf` cr, MonadIO cr)+hGetPosn ∷ (pr `AncestorRegion` cr, MonadIO cr)          ⇒ RegionalFileHandle ioMode pr → cr HandlePosn hGetPosn = wrap E.hGetPosn @@ -576,13 +592,13 @@ --  * 'isPermissionError' if a system resource limit would be exceeded. -- -- Wraps: @System.IO.'SIO.hSeek'@.-hSeek ∷ (pr `ParentOf` cr, MonadIO cr)+hSeek ∷ (pr `AncestorRegion` cr, MonadIO cr)       ⇒ RegionalFileHandle ioMode pr → SeekMode → Integer → cr () hSeek = wrap3 E.hSeek  #if !defined(__NHC__) -- | Wraps: @System.IO.'SIO.hTell'@.-hTell ∷ (pr `ParentOf` cr, MonadIO cr)+hTell ∷ (pr `AncestorRegion` cr, MonadIO cr)       ⇒ RegionalFileHandle ioMode pr → cr Integer hTell = wrap E.hTell #endif@@ -595,7 +611,7 @@ -- for testing the correctness of this library. -- -- Wraps: @System.IO.'SIO.hIsOpen'@.-hIsOpen ∷ (pr `ParentOf` cr, MonadIO cr)+hIsOpen ∷ (pr `AncestorRegion` cr, MonadIO cr)          ⇒ RegionalFileHandle ioMode pr → cr Bool hIsOpen = wrap E.hIsOpen @@ -604,7 +620,7 @@ -- for testing the correctness of this library. -- -- Wraps: @System.IO.'SIO.hIsClosed'@.-hIsClosed ∷ (pr `ParentOf` cr, MonadIO cr)+hIsClosed ∷ (pr `AncestorRegion` cr, MonadIO cr)            ⇒ RegionalFileHandle ioMode pr → cr Bool hIsClosed = wrap E.hIsClosed @@ -613,7 +629,7 @@ -- correctness of this library. -- -- Wraps: @System.IO.'SIO.hIsReadable'@.-hIsReadable ∷ (pr `ParentOf` cr, MonadIO cr)+hIsReadable ∷ (pr `AncestorRegion` cr, MonadIO cr)             ⇒ RegionalFileHandle ioMode pr → cr Bool hIsReadable = wrap E.hIsReadable @@ -622,12 +638,12 @@ -- correctness of this library. -- -- Wraps: @System.IO.'SIO.hIsWritable'@.-hIsWritable ∷ (pr `ParentOf` cr, MonadIO cr)+hIsWritable ∷ (pr `AncestorRegion` cr, MonadIO cr)             ⇒ RegionalFileHandle ioMode pr → cr Bool hIsWritable = wrap E.hIsWritable  -- | Wraps: @System.IO.'SIO.hIsSeekable'@.-hIsSeekable ∷ (pr `ParentOf` cr, MonadIO cr)+hIsSeekable ∷ (pr `AncestorRegion` cr, MonadIO cr)             ⇒ RegionalFileHandle ioMode pr → cr Bool hIsSeekable = wrap E.hIsSeekable @@ -638,21 +654,21 @@ -- | Is the handle connected to a terminal? -- -- Wraps: @System.IO.'SIO.hIsTerminalDevice'@.-hIsTerminalDevice ∷ (pr `ParentOf` cr, MonadIO cr)+hIsTerminalDevice ∷ (pr `AncestorRegion` cr, MonadIO cr)                   ⇒ RegionalFileHandle ioMode pr → cr Bool hIsTerminalDevice = wrap E.hIsTerminalDevice  -- | Set the echoing status of a handle connected to a terminal. -- -- Wraps: @System.IO.'SIO.hSetEcho'@.-hSetEcho ∷ (pr `ParentOf` cr, MonadIO cr)+hSetEcho ∷ (pr `AncestorRegion` cr, MonadIO cr)          ⇒ RegionalFileHandle ioMode pr → Bool → cr () hSetEcho = wrap2 E.hSetEcho  -- | Get the echoing status of a handle connected to a terminal. -- -- Wraps: @System.IO.'SIO.hGetEcho'@.-hGetEcho ∷ (pr `ParentOf` cr, MonadIO cr)+hGetEcho ∷ (pr `AncestorRegion` cr, MonadIO cr)          ⇒ RegionalFileHandle ioMode pr → cr Bool hGetEcho = wrap E.hGetEcho #endif@@ -662,7 +678,7 @@  #ifdef __GLASGOW_HASKELL__ -- | Wraps: @System.IO.'SIO.hShow'@.-hShow ∷ (pr `ParentOf` cr, MonadIO cr)+hShow ∷ (pr `AncestorRegion` cr, MonadIO cr)       ⇒ RegionalFileHandle ioMode pr → cr String hShow = wrap E.hShow #endif@@ -691,7 +707,7 @@ -- @safe@ foreign call in this respect. -- -- Wraps: @System.IO.'SIO.hWaitForInput'@.-hWaitForInput ∷ (pr `ParentOf` cr, MonadIO cr, ReadModes ioMode)+hWaitForInput ∷ (pr `AncestorRegion` cr, MonadIO cr, ReadModes ioMode)               ⇒ RegionalFileHandle ioMode pr → Int → cr Bool hWaitForInput = wrap2 E.hWaitForInput @@ -703,7 +719,7 @@ --  * 'isEOFError' if the end of file has been reached. -- -- Wraps: @System.IO.'SIO.hReady'@.-hReady ∷ (pr `ParentOf` cr, MonadIO cr, ReadModes ioMode)+hReady ∷ (pr `AncestorRegion` cr, MonadIO cr, ReadModes ioMode)        ⇒ RegionalFileHandle ioMode pr → cr Bool hReady = wrap E.hReady @@ -715,7 +731,7 @@ --  * 'isEOFError' if the end of file has been reached. -- -- Wraps: @System.IO.'SIO.hGetChar'@.-hGetChar ∷ (pr `ParentOf` cr, MonadIO cr, ReadModes ioMode)+hGetChar ∷ (pr `AncestorRegion` cr, MonadIO cr, ReadModes ioMode)          ⇒ RegionalFileHandle ioMode pr → cr Char hGetChar = wrap E.hGetChar @@ -732,7 +748,7 @@ -- line is returned. -- -- Wraps: @System.IO.'SIO.hGetLine'@.-hGetLine ∷ (pr `ParentOf` cr, MonadIO cr, ReadModes ioMode)+hGetLine ∷ (pr `AncestorRegion` cr, MonadIO cr, ReadModes ioMode)          ⇒ RegionalFileHandle ioMode pr → cr String hGetLine = wrap E.hGetLine @@ -745,7 +761,7 @@ --  * 'isEOFError' if the end of file has been reached. -- -- Wraps: @System.IO.'SIO.hLookAhead'@.-hLookAhead ∷ (pr `ParentOf` cr, MonadIO cr, ReadModes ioMode)+hLookAhead ∷ (pr `AncestorRegion` cr, MonadIO cr, ReadModes ioMode)            ⇒ RegionalFileHandle ioMode pr → cr Char hLookAhead = wrap E.hLookAhead @@ -779,7 +795,7 @@ --  * 'isEOFError' if the end of file has been reached. -- -- Wraps: @System.IO.'SIO.hGetContents'@.-hGetContents ∷ (pr `ParentOf` cr, MonadIO cr, ReadModes ioMode)+hGetContents ∷ (pr `AncestorRegion` cr, MonadIO cr, ReadModes ioMode)              ⇒ RegionalFileHandle ioMode pr → cr String hGetContents = wrap E.hGetContents @@ -797,7 +813,7 @@ --  * 'isPermissionError' if another system resource limit would be exceeded. -- -- Wraps: @System.IO.'SIO.hPutChar'@.-hPutChar ∷ (pr `ParentOf` cr, MonadIO cr, WriteModes ioMode)+hPutChar ∷ (pr `AncestorRegion` cr, MonadIO cr, WriteModes ioMode)          ⇒ RegionalFileHandle ioMode pr → Char → cr () hPutChar = wrap2 E.hPutChar @@ -811,14 +827,14 @@ --  * 'isPermissionError' if another system resource limit would be exceeded. -- -- Wraps: @System.IO.'SIO.hPutStr'@.-hPutStr ∷ (pr `ParentOf` cr, MonadIO cr, WriteModes ioMode)+hPutStr ∷ (pr `AncestorRegion` cr, MonadIO cr, WriteModes ioMode)         ⇒ RegionalFileHandle ioMode pr → String → cr () hPutStr = wrap2 E.hPutStr  -- | The same as 'hPutStr', but adds a newline character. -- -- Wraps: @System.IO.'SIO.hPutStrLn'@.-hPutStrLn ∷ (pr `ParentOf` cr, MonadIO cr, WriteModes ioMode)+hPutStrLn ∷ (pr `AncestorRegion` cr, MonadIO cr, WriteModes ioMode)           ⇒ RegionalFileHandle ioMode pr → String → cr () hPutStrLn = wrap2 E.hPutStrLn @@ -833,7 +849,7 @@ --  * 'isPermissionError' if another system resource limit would be exceeded. -- -- Wraps: @System.IO.'SIO.hPrint'@.-hPrint ∷ (pr `ParentOf` cr, MonadIO cr, WriteModes ioMode, Show α)+hPrint ∷ (pr `AncestorRegion` cr, MonadIO cr, WriteModes ioMode, Show α)        ⇒ RegionalFileHandle ioMode pr → α → cr () hPrint = wrap2 E.hPrint @@ -895,7 +911,7 @@ -- characters.  (See also 'hSetBinaryMode'.) -- -- This provides a safer replacement for @System.IO.'SIO.openBinaryFile'@.-openBinaryFile ∷ (MonadCatchIO pr, AbsRelClass ar)+openBinaryFile ∷ (MonadPeelIO pr, AbsRelClass ar)                ⇒ FilePath ar                → IOMode ioMode                → RegionT s pr@@ -907,7 +923,7 @@ resulting region. This provides a safer replacement for @System.IO.'SIO.withBinaryFile'@. -}-withBinaryFile ∷ (MonadCatchIO pr, AbsRelClass ar)+withBinaryFile ∷ (MonadPeelIO pr, AbsRelClass ar)                ⇒ FilePath ar                → IOMode ioMode                →  (∀ s. RegionalFileHandle ioMode (RegionT s pr) → RegionT s pr α)@@ -917,14 +933,14 @@ -- ** Opening binary files by inferring the IOMode  -- | Note that: @openBinaryFile' filePath = 'openBinaryFile' filePath 'mkIOMode'@.-openBinaryFile' ∷ (MonadCatchIO pr, AbsRelClass ar, MkIOMode ioMode)+openBinaryFile' ∷ (MonadPeelIO pr, AbsRelClass ar, MkIOMode ioMode)                 ⇒ FilePath ar                 → RegionT s pr                     (RegionalFileHandle ioMode (RegionT s pr)) openBinaryFile' filePath = openBinaryFile filePath mkIOMode  -- | Note that: @withBinaryFile' filePath = 'withBinaryFile' filePath 'mkIOMode'@.-withBinaryFile' ∷ (MonadCatchIO pr, AbsRelClass ar, MkIOMode ioMode)+withBinaryFile' ∷ (MonadPeelIO pr, AbsRelClass ar, MkIOMode ioMode)                 ⇒ FilePath ar                 →  (∀ s. RegionalFileHandle ioMode (RegionT s pr) → RegionT s pr α)                 → pr α@@ -939,7 +955,7 @@ -- with 'hSetNewlineMode' with 'noNewlineTranslation'. -- -- Wraps: @System.IO.'SIO.hSetBinaryMode'@.-hSetBinaryMode ∷ (pr `ParentOf` cr, MonadIO cr)+hSetBinaryMode ∷ (pr `AncestorRegion` cr, MonadIO cr)                ⇒ RegionalFileHandle ioMode pr → Bool → cr () hSetBinaryMode = wrap2 E.hSetBinaryMode @@ -960,8 +976,8 @@ --    instead, whose default action is to terminate the program). -- -- Wraps: @System.IO.'SIO.hPutBuf'@.-hPutBuf ∷ ( pr1 `ParentOf` cr-          , pr2 `ParentOf` cr+hPutBuf ∷ ( pr1 `AncestorRegion` cr+          , pr2 `AncestorRegion` cr           , MonadIO cr           , WriteModes ioMode           )@@ -995,8 +1011,8 @@ -- 'RegionalFileHandle', and reads bytes directly. -- -- Wraps: @System.IO.'SIO.hGetBuf'@.-hGetBuf ∷ ( pr1 `ParentOf` cr-          , pr2 `ParentOf` cr+hGetBuf ∷ ( pr1 `AncestorRegion` cr+          , pr2 `AncestorRegion` cr           , MonadIO cr           , ReadModes ioMode           )@@ -1007,9 +1023,41 @@ hGetBuf = wrapPtr E.hGetBuf  #if !defined(__NHC__) && !defined(__HUGS__)++#if MIN_VERSION_base(4,3,0)+-- | 'hGetBufSome' @hdl buf count@ reads data from the handle @hdl@+-- into the buffer @buf@.  If there is any data available to read,+-- then 'hGetBufSome' returns it immediately; it only blocks if there+-- is no data to be read.+--+-- It returns the number of bytes actually read.  This may be zero if+-- EOF was reached before any data was read (or if @count@ is zero).+--+-- 'hGetBufSome' never raises an EOF exception, instead it returns a value+-- smaller than @count@.+--+-- If the handle is a pipe or socket, and the writing end+-- is closed, 'hGetBufSome' will behave as if EOF was reached.+--+-- 'hGetBufSome' ignores the prevailing 'TextEncoding' and 'NewlineMode'+-- on the 'Handle', and reads bytes directly.+--+-- Wraps: @System.IO.'SIO.hGetBufSome'@.+hGetBufSome ∷ ( pr1 `AncestorRegion` cr+              , pr2 `AncestorRegion` cr+              , MonadIO cr+              , ReadModes ioMode+              )+            ⇒ RegionalFileHandle ioMode pr1+            → RegionalPtr α pr2+            → Int+            → cr Int+hGetBufSome = wrapPtr E.hGetBufSome+#endif+ -- | Wraps: @System.IO.'SIO.hPutBufNonBlocking'@.-hPutBufNonBlocking ∷ ( pr1 `ParentOf` cr-                     , pr2 `ParentOf` cr+hPutBufNonBlocking ∷ ( pr1 `AncestorRegion` cr+                     , pr2 `AncestorRegion` cr                      , MonadIO cr                      , WriteModes ioMode                      )@@ -1039,8 +1087,8 @@ -- on the 'RegionalFileHandle', and reads bytes directly. -- -- Wraps: @System.IO.'SIO.hGetBufNonBlocking'@.-hGetBufNonBlocking ∷ ( pr1 `ParentOf` cr-                     , pr2 `ParentOf` cr+hGetBufNonBlocking ∷ ( pr1 `AncestorRegion` cr+                     , pr2 `AncestorRegion` cr                      , MonadIO cr                      , ReadModes ioMode                      )@@ -1062,7 +1110,7 @@ -- where XXX is some random number. type Template = RelFile -openTemp ∷ (MonadCatchIO pr, AbsRelClass ar)+openTemp ∷ (MonadPeelIO pr, AbsRelClass ar)          ⇒ (E.FilePath → String → IO (E.FilePath, E.Handle ReadWriteMode))          → ( DirPath ar            → Template@@ -1090,7 +1138,7 @@ -- so if you rely on this behaviour it is best to use local filesystems only. -- -- This provides a safer replacement for @System.IO.'SIO.openTempFile'@.-openTempFile ∷ (MonadCatchIO pr, AbsRelClass ar)+openTempFile ∷ (MonadPeelIO pr, AbsRelClass ar)              ⇒ DirPath ar -- ^ Directory in which to create the file.              → Template   -- ^ File name template.              → RegionT s pr ( AbsFile@@ -1103,7 +1151,7 @@ -- -- This provides a safer replacement for @System.IO.'SIO.openBinaryTempFile'@. openBinaryTempFile ∷-    (MonadCatchIO pr, AbsRelClass ar)+    (MonadPeelIO pr, AbsRelClass ar)   ⇒ DirPath ar   → Template   → RegionT s pr ( AbsFile@@ -1117,7 +1165,7 @@ -- This provides a safer replacement for -- @System.IO.'SIO.openTempFileWithDefaultPermissions'@. openTempFileWithDefaultPermissions ∷-    (MonadCatchIO pr, AbsRelClass ar)+    (MonadPeelIO pr, AbsRelClass ar)   ⇒ DirPath ar   → Template   → RegionT s pr ( AbsFile@@ -1130,7 +1178,7 @@ -- This provides a safer replacement for -- @System.IO.'SIO.openBinaryTempFileWithDefaultPermissions'@. openBinaryTempFileWithDefaultPermissions ∷-    (MonadCatchIO pr, AbsRelClass ar)+    (MonadPeelIO pr, AbsRelClass ar)   ⇒ DirPath ar   → Template   → RegionT s pr ( AbsFile@@ -1158,7 +1206,7 @@ -- the encoding. -- -- Wraps: @System.IO.'SIO.hSetEncoding'@.-hSetEncoding ∷ (pr `ParentOf` cr, MonadIO cr)+hSetEncoding ∷ (pr `AncestorRegion` cr, MonadIO cr)              ⇒ RegionalFileHandle ioMode pr → TextEncoding → cr () hSetEncoding = wrap2 E.hSetEncoding @@ -1172,7 +1220,7 @@ -- written to the file. -- -- Wraps: @System.IO.'SIO.hGetEncoding'@.-hGetEncoding ∷ (pr `ParentOf` cr, MonadIO cr)+hGetEncoding ∷ (pr `AncestorRegion` cr, MonadIO cr)              ⇒ RegionalFileHandle ioMode pr → cr (Maybe TextEncoding) hGetEncoding = wrap E.hGetEncoding @@ -1189,7 +1237,7 @@ -- data is flushed first. -- -- Wraps: @System.IO.'SIO.hSetNewlineMode'@.-hSetNewlineMode ∷ (pr `ParentOf` cr, MonadIO cr)+hSetNewlineMode ∷ (pr `AncestorRegion` cr, MonadIO cr)                 ⇒ RegionalFileHandle ioMode pr → NewlineMode → cr () hSetNewlineMode = wrap2 E.hSetNewlineMode #endif
System/IO/SaferFileHandles/Internal.hs view
@@ -22,13 +22,16 @@ --------------------------------------------------------------------------------  -- from base:-import Control.Monad                     ( return, (>>=), fail )+import Control.Monad                     ( return, liftM ) import Data.Function                     ( ($) ) import Data.Maybe                        ( Maybe(Nothing, Just) ) +-- from base-unicode-symbols:+import Data.Function.Unicode             ( (∘) )+ -- from regions: import Control.Monad.Trans.Region        ( Dup(dup) )-import Control.Monad.Trans.Region.OnExit ( CloseHandle )+import Control.Monad.Trans.Region.OnExit ( FinalizerHandle )  -- from explicit-iomodes import System.IO.ExplicitIOModes         ( Handle )@@ -45,13 +48,11 @@ -- | A regional handle to an opened file parameterized by the 'IOMode' in which -- you opened the file and the region in which it was created. data RegionalFileHandle ioMode (r ∷ * → *) =-    RegionalFileHandle !(Handle ioMode) !(Maybe (CloseHandle r))+    RegionalFileHandle !(Handle ioMode) !(Maybe (FinalizerHandle r))  instance Dup (RegionalFileHandle ioMode) where     dup (RegionalFileHandle h Nothing)   = return $ RegionalFileHandle h Nothing-    dup (RegionalFileHandle h (Just ch)) = do ch' ← dup ch-                                              return $ RegionalFileHandle h-                                                     $ Just ch'+    dup (RegionalFileHandle h (Just ch)) = liftM (RegionalFileHandle h ∘ Just) $ dup ch   -- The End ---------------------------------------------------------------------
safer-file-handles.cabal view
@@ -1,5 +1,5 @@ name:          safer-file-handles-version:       0.8+version:       0.9 cabal-version: >=1.6 build-type:    Custom license:       BSD3@@ -51,14 +51,14 @@  Library   GHC-Options: -Wall-  build-depends: base                      >= 4     && < 4.3+  build-depends: base                      >= 4     && < 4.4                , base-unicode-symbols      >= 0.1.1 && < 0.3-               , regions                   >= 0.6   && < 0.8+               , regions                   >= 0.8   && < 0.9                , transformers              >= 0.2   && < 0.3-               , MonadCatchIO-transformers >= 0.2   && < 0.3-               , explicit-iomodes          >= 0.5   && < 0.6+               , monad-peel                >= 0.1   && < 0.3+               , explicit-iomodes          >= 0.5   && < 0.7                , pathtype                  >= 0.0.1 && < 0.6-               , regional-pointers         >= 0.4   && < 0.5+               , regional-pointers         >= 0.5   && < 0.6   exposed-modules: System.IO.SaferFileHandles                    System.IO.SaferFileHandles.Unsafe   other-modules:   System.IO.SaferFileHandles.Internal