explicit-iomodes 0.2 → 0.3
raw patch · 8 files changed
+117/−96 lines, 8 filesdep ~base-unicode-symbolsPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base-unicode-symbols
API changes (from Hackage documentation)
- System.IO.ExplicitIOModes: data A
- System.IO.ExplicitIOModes: data R
- System.IO.ExplicitIOModes: data RW
- System.IO.ExplicitIOModes: data W
- System.IO.ExplicitIOModes: instance CheckMode A
- System.IO.ExplicitIOModes: instance CheckMode R
- System.IO.ExplicitIOModes: instance CheckMode RW
- System.IO.ExplicitIOModes: instance CheckMode W
- System.IO.ExplicitIOModes: instance ReadModes R
- System.IO.ExplicitIOModes: instance ReadModes RW
- System.IO.ExplicitIOModes: instance WriteModes A
- System.IO.ExplicitIOModes: instance WriteModes RW
- System.IO.ExplicitIOModes: instance WriteModes W
+ System.IO.ExplicitIOModes: data AppendMode
+ System.IO.ExplicitIOModes: data ReadMode
+ System.IO.ExplicitIOModes: data ReadWriteMode
+ System.IO.ExplicitIOModes: data WriteMode
+ System.IO.ExplicitIOModes: instance CheckMode AppendMode
+ System.IO.ExplicitIOModes: instance CheckMode ReadMode
+ System.IO.ExplicitIOModes: instance CheckMode ReadWriteMode
+ System.IO.ExplicitIOModes: instance CheckMode WriteMode
+ System.IO.ExplicitIOModes: instance ReadModes ReadMode
+ System.IO.ExplicitIOModes: instance ReadModes ReadWriteMode
+ System.IO.ExplicitIOModes: instance WriteModes AppendMode
+ System.IO.ExplicitIOModes: instance WriteModes ReadWriteMode
+ System.IO.ExplicitIOModes: instance WriteModes WriteMode
- System.IO.ExplicitIOModes: AppendMode :: IOMode A
+ System.IO.ExplicitIOModes: AppendMode :: IOMode AppendMode
- System.IO.ExplicitIOModes: ReadMode :: IOMode R
+ System.IO.ExplicitIOModes: ReadMode :: IOMode ReadMode
- System.IO.ExplicitIOModes: ReadWriteMode :: IOMode RW
+ System.IO.ExplicitIOModes: ReadWriteMode :: IOMode ReadWriteMode
- System.IO.ExplicitIOModes: WriteMode :: IOMode W
+ System.IO.ExplicitIOModes: WriteMode :: IOMode WriteMode
- System.IO.ExplicitIOModes: openBinaryTempFile :: FilePath -> String -> IO (FilePath, Handle RW)
+ System.IO.ExplicitIOModes: openBinaryTempFile :: FilePath -> String -> IO (FilePath, Handle ReadWriteMode)
- System.IO.ExplicitIOModes: openBinaryTempFileWithDefaultPermissions :: FilePath -> String -> IO (FilePath, Handle RW)
+ System.IO.ExplicitIOModes: openBinaryTempFileWithDefaultPermissions :: FilePath -> String -> IO (FilePath, Handle ReadWriteMode)
- System.IO.ExplicitIOModes: openTempFile :: FilePath -> String -> IO (FilePath, Handle RW)
+ System.IO.ExplicitIOModes: openTempFile :: FilePath -> String -> IO (FilePath, Handle ReadWriteMode)
- System.IO.ExplicitIOModes: openTempFileWithDefaultPermissions :: FilePath -> String -> IO (FilePath, Handle RW)
+ System.IO.ExplicitIOModes: openTempFileWithDefaultPermissions :: FilePath -> String -> IO (FilePath, Handle ReadWriteMode)
- System.IO.ExplicitIOModes: stderr :: Handle W
+ System.IO.ExplicitIOModes: stderr :: Handle WriteMode
- System.IO.ExplicitIOModes: stdin :: Handle R
+ System.IO.ExplicitIOModes: stdin :: Handle ReadMode
- System.IO.ExplicitIOModes: stdout :: Handle W
+ System.IO.ExplicitIOModes: stdout :: Handle WriteMode
Files
- Data/ByteString/Char8/ExplicitIOModes.hs +1/−1
- Data/ByteString/ExplicitIOModes.hs +1/−1
- Data/ByteString/Lazy/Char8/ExplicitIOModes.hs +1/−1
- Data/ByteString/Lazy/ExplicitIOModes.hs +1/−1
- LICENSE +1/−1
- System/IO/ExplicitIOModes.hs +101/−80
- System/IO/ExplicitIOModes/Internal.hs +8/−8
- explicit-iomodes.cabal +3/−3
Data/ByteString/Char8/ExplicitIOModes.hs view
@@ -3,7 +3,7 @@ ------------------------------------------------------------------------------- -- | -- Module : Data.ByteString.ExplicitIOModes--- Copyright : (c) 2009 Bas van Dijk+-- Copyright : (c) 2009-2010 Bas van Dijk -- License : BSD3 (see the file LICENSE) -- Maintainer : Bas van Dijk <v.dijk.bas@gmail.com> --
Data/ByteString/ExplicitIOModes.hs view
@@ -3,7 +3,7 @@ ------------------------------------------------------------------------------- -- | -- Module : Data.ByteString.ExplicitIOModes--- Copyright : (c) 2009 Bas van Dijk+-- Copyright : (c) 2009-2010 Bas van Dijk -- License : BSD3 (see the file LICENSE) -- Maintainer : Bas van Dijk <v.dijk.bas@gmail.com> --
Data/ByteString/Lazy/Char8/ExplicitIOModes.hs view
@@ -3,7 +3,7 @@ ------------------------------------------------------------------------------- -- | -- Module : Data.ByteString.ExplicitIOModes--- Copyright : (c) 2009 Bas van Dijk+-- Copyright : (c) 2009-2010 Bas van Dijk -- License : BSD3 (see the file LICENSE) -- Maintainer : Bas van Dijk <v.dijk.bas@gmail.com> --
Data/ByteString/Lazy/ExplicitIOModes.hs view
@@ -3,7 +3,7 @@ ------------------------------------------------------------------------------- -- | -- Module : Data.ByteString.ExplicitIOModes--- Copyright : (c) 2009 Bas van Dijk+-- Copyright : (c) 2009-2010 Bas van Dijk -- License : BSD3 (see the file LICENSE) -- Maintainer : Bas van Dijk <v.dijk.bas@gmail.com> --
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2009 Bas van Dijk+Copyright (c) 2009-2010 Bas van Dijk All rights reserved.
System/IO/ExplicitIOModes.hs view
@@ -9,7 +9,7 @@ ------------------------------------------------------------------------------- -- | -- Module : System.IO.ExplicitIOModes--- Copyright : (c) 2009 Bas van Dijk+-- Copyright : (c) 2009-2010 Bas van Dijk -- License : BSD3 (see the file LICENSE) -- Maintainer : Bas van Dijk <v.dijk.bas@gmail.com> --@@ -24,8 +24,8 @@ -- -- There's one exception to this last statement: If you are using the standard -- handles 'stdin', 'stdout' or 'stderr' in a mode which isn't their default--- mode ('R' for 'stdin' and 'W' for 'stdout' and 'stderr') you have to 'cast'--- these handles to the expected IOMode.+-- mode ('ReadMode' for 'stdin' and 'WriteMode' for 'stdout' and 'stderr') you+-- have to 'cast' these handles to the expected IOMode. -- -------------------------------------------------------------------------------- @@ -42,10 +42,17 @@ -- ** IO Modes -- | Types that represent the IOMode a 'Handle' can be in.- , R, W, A, RW+ , IOMode(..)+ , regularIOMode - , ReadModes, WriteModes+ , ReadMode+ , WriteMode+ , AppendMode+ , ReadWriteMode + , ReadModes+ , WriteModes+ -- ** Standard handles -- | These standard handles have concrete IOModes by default which work@@ -62,8 +69,6 @@ -- ** Opening files , withFile , openFile- , IOMode(..)- , regularIOMode -- ** Closing files , hClose@@ -125,7 +130,7 @@ -- | Note that the following text input operations are polymorphic in the -- IOMode of the given handle. However the IOModes are restricted to- -- 'ReadModes' only which can be either 'R' or 'RW'.+ -- 'ReadModes' only which can be either 'ReadMode' or 'ReadWriteMode'. , hWaitForInput , hReady , hGetChar@@ -137,7 +142,8 @@ -- | Note that the following text output operations are polymorphic in the -- IOMode of the given handle. However the IOModes are restricted to- -- 'WriteModes' only which can be either 'W', 'A' or 'RW'.+ -- 'WriteModes' only which can be either 'WriteMode', 'AppendMode' or+ -- 'ReadWriteMode'. , hPutChar , hPutStr , hPutStrLn@@ -204,6 +210,10 @@ ) where +--------------------------------------------------------------------------------+-- Imports+--------------------------------------------------------------------------------+ -- from base: import Prelude ( Integer ) import Control.Monad ( return, (>>=), fail, liftM, liftM2 )@@ -232,21 +242,71 @@ import System.IO.ExplicitIOModes.Internal ( Handle(Handle), wrap) +-------------------------------------------------------------------------------- -- * Files and handles+-------------------------------------------------------------------------------- -- ** IO Modes +-- | The IOMode GADT which for each constructor specifies the associated IOMode+-- type.+--+-- 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'.+regularIOMode ∷ IOMode ioMode → SIO.IOMode+regularIOMode ReadMode = SIO.ReadMode+regularIOMode WriteMode = SIO.WriteMode+regularIOMode AppendMode = SIO.AppendMode+regularIOMode ReadWriteMode = SIO.ReadWriteMode++instance Eq (IOMode ioMode) where+ ReadMode == ReadMode = True+ WriteMode == WriteMode = True+ AppendMode == AppendMode = True+ ReadWriteMode == ReadWriteMode = True+ _ == _ = False++instance Ord (IOMode ioMode) where+ ReadWriteMode <= ReadWriteMode = True+ ReadWriteMode <= _ = False++ AppendMode <= ReadWriteMode = True+ AppendMode <= AppendMode = True+ AppendMode <= _ = False++ WriteMode <= ReadWriteMode = True+ WriteMode <= AppendMode = True+ WriteMode <= WriteMode = True+ WriteMode <= _ = False++ ReadMode <= ReadWriteMode = True+ ReadMode <= AppendMode = True+ ReadMode <= WriteMode = True+ ReadMode <= ReadMode = True++instance Show (IOMode ioMode) where+ show ReadMode = "ReadMode"+ show WriteMode = "WriteMode"+ show AppendMode = "AppendMode"+ show ReadWriteMode = "ReadWriteMode"+ -- | Read only.-data R+data ReadMode -- | Write only.-data W+data WriteMode -- | Write only by appending.-data A+data AppendMode -- | Both read and write.-data RW+data ReadWriteMode -- | Class of readable IO mode types. class ReadModes ioMode@@ -254,25 +314,25 @@ -- | Class of writable IO mode types. class WriteModes ioMode -instance ReadModes R-instance ReadModes RW+instance ReadModes ReadMode+instance ReadModes ReadWriteMode -instance WriteModes W-instance WriteModes A-instance WriteModes RW+instance WriteModes WriteMode+instance WriteModes AppendMode+instance WriteModes ReadWriteMode -- ** Standard handles -- | Wraps: @System.IO.@'SIO.stdin'.-stdin ∷ Handle R+stdin ∷ Handle ReadMode stdin = Handle SIO.stdin -- | Wraps: @System.IO.@'SIO.stdout'.-stdout ∷ Handle W+stdout ∷ Handle WriteMode stdout = Handle SIO.stdout -- | Wraps: @System.IO.@'SIO.stderr'.-stderr ∷ Handle W+stderr ∷ Handle WriteMode stderr = Handle SIO.stderr -- | Cast the IOMode of a handle if the handle supports it.@@ -287,22 +347,23 @@ class CheckMode ioMode where checkMode ∷ Tagged ioMode (SIO.Handle → IO Bool) -instance CheckMode R where+instance CheckMode ReadMode where checkMode = Tagged SIO.hIsReadable -instance CheckMode W where+instance CheckMode WriteMode where checkMode = Tagged SIO.hIsWritable -instance CheckMode A where+instance CheckMode AppendMode where checkMode = Tagged SIO.hIsWritable -instance CheckMode RW where+instance CheckMode ReadWriteMode where checkMode = Tagged $ \h → liftM2 (∧) (SIO.hIsReadable h) (SIO.hIsWritable h) +-------------------------------------------------------------------------------- -- * Opening and closing files-+-------------------------------------------------------------------------------- -- ** Opening files @@ -314,54 +375,6 @@ openFile ∷ FilePath → IOMode ioMode → IO (Handle ioMode) openFile fp = liftM Handle ∘ SIO.openFile fp ∘ regularIOMode --- | The IOMode GADT which for each constructor specifies the associated IOMode--- type.------ Also see: @System.IO.@'SIO.IOMode'.-data IOMode ioMode where- ReadMode ∷ IOMode R- WriteMode ∷ IOMode W- AppendMode ∷ IOMode A- ReadWriteMode ∷ IOMode RW---- | Retrieves the regular @System.IO.@'SIO.IOMode'.-regularIOMode ∷ IOMode ioMode → SIO.IOMode-regularIOMode ReadMode = SIO.ReadMode-regularIOMode WriteMode = SIO.WriteMode-regularIOMode AppendMode = SIO.AppendMode-regularIOMode ReadWriteMode = SIO.ReadWriteMode--instance Eq (IOMode ioMode) where- ReadMode == ReadMode = True- WriteMode == WriteMode = True- AppendMode == AppendMode = True- ReadWriteMode == ReadWriteMode = True- _ == _ = False--instance Ord (IOMode ioMode) where- ReadWriteMode <= ReadWriteMode = True- ReadWriteMode <= _ = False-- AppendMode <= ReadWriteMode = True- AppendMode <= AppendMode = True- AppendMode <= _ = False-- WriteMode <= ReadWriteMode = True- WriteMode <= AppendMode = True- WriteMode <= WriteMode = True- WriteMode <= _ = False-- ReadMode <= ReadWriteMode = True- ReadMode <= AppendMode = True- ReadMode <= WriteMode = True- ReadMode <= ReadMode = True--instance Show (IOMode ioMode) where- show ReadMode = "ReadMode"- show WriteMode = "WriteMode"- show AppendMode = "AppendMode"- show ReadWriteMode = "ReadWriteMode"- -- ** Closing files -- | Wraps: @System.IO.@'SIO.hClose'.@@ -369,8 +382,9 @@ hClose = wrap SIO.hClose +-------------------------------------------------------------------------------- -- * Operations on handles-+-------------------------------------------------------------------------------- -- ** Determining and changing the size of a file @@ -470,7 +484,9 @@ #endif +-------------------------------------------------------------------------------- -- * Text input and output+-------------------------------------------------------------------------------- -- ** Text input @@ -518,7 +534,9 @@ hPrint = wrap SIO.hPrint +-------------------------------------------------------------------------------- -- * Binary input and output+-------------------------------------------------------------------------------- -- | Wraps: @System.IO.@'SIO.withBinaryFile'. withBinaryFile ∷ FilePath → IOMode ioMode → (Handle ioMode → IO r) → IO r@@ -551,24 +569,26 @@ #endif +-------------------------------------------------------------------------------- -- * Temporary files+-------------------------------------------------------------------------------- -- | Wraps: @System.IO.@'SIO.openTempFile'.-openTempFile ∷ FilePath → String → IO (FilePath, Handle RW)+openTempFile ∷ FilePath → String → IO (FilePath, Handle ReadWriteMode) openTempFile fp template = liftM (second Handle) $ SIO.openTempFile fp template -- | Wraps: @System.IO.@'SIO.openBinaryTempFile'.-openBinaryTempFile ∷ FilePath → String → IO (FilePath, Handle RW)+openBinaryTempFile ∷ FilePath → String → IO (FilePath, Handle ReadWriteMode) openBinaryTempFile fp template = liftM (second Handle) $ SIO.openBinaryTempFile fp template #if MIN_VERSION_base(4,2,0)-openTempFileWithDefaultPermissions ∷ FilePath → String → IO (FilePath, Handle RW)+openTempFileWithDefaultPermissions ∷ FilePath → String → IO (FilePath, Handle ReadWriteMode) openTempFileWithDefaultPermissions fp template = liftM (second Handle) $ SIO.openTempFileWithDefaultPermissions fp template -openBinaryTempFileWithDefaultPermissions ∷ FilePath → String → IO (FilePath, Handle RW)+openBinaryTempFileWithDefaultPermissions ∷ FilePath → String → IO (FilePath, Handle ReadWriteMode) openBinaryTempFileWithDefaultPermissions fp template = liftM (second Handle) $ SIO.openBinaryTempFileWithDefaultPermissions fp template #endif@@ -583,12 +603,13 @@ hGetEncoding = wrap SIO.hGetEncoding +-------------------------------------------------------------------------------- -- * Newline conversion+-------------------------------------------------------------------------------- hSetNewlineMode ∷ Handle ioMode → SIO.NewlineMode → IO () hSetNewlineMode = wrap SIO.hSetNewlineMode #endif- -- The End ---------------------------------------------------------------------
System/IO/ExplicitIOModes/Internal.hs view
@@ -3,22 +3,22 @@ module System.IO.ExplicitIOModes.Internal where -- from base:-import Text.Show ( Show )-import Data.Eq ( Eq )-import Data.Typeable ( Typeable )-import qualified System.IO as SIO ( Handle )+import Text.Show ( Show )+import Data.Eq ( Eq )+import Data.Typeable ( Typeable )+import qualified System.IO ( Handle ) -- | A handle to a file with an explicit IOMode. -- -- Wraps: @System.IO.@'SIO.Handle'. newtype Handle ioMode = Handle- { -- | Retrieves the regular @System.IO.@'SIO.Handle'.- regularHandle ∷ SIO.Handle+ { -- | Retrieves the regular @System.IO.@'System.IO.Handle'.+ regularHandle ∷ System.IO.Handle } deriving ( Show, Eq, Typeable ) -wrap ∷ (SIO.Handle → α) → (Handle ioMode → α)+wrap ∷ (System.IO.Handle → α) → (Handle ioMode → α) wrap f = \h → f (regularHandle h) -wrap2 ∷ (SIO.Handle → β → α) → (Handle ioMode → β → α)+wrap2 ∷ (System.IO.Handle → β → α) → (Handle ioMode → β → α) wrap2 f = \h y → f (regularHandle h) y
explicit-iomodes.cabal view
@@ -1,10 +1,10 @@ name: explicit-iomodes-version: 0.2+version: 0.3 cabal-version: >=1.6 build-type: Simple license: BSD3 license-file: LICENSE-copyright: 2009 Bas van Dijk+copyright: 2009-2010 Bas van Dijk author: Bas van Dijk maintainer: Bas van Dijk <v.dijk.bas@gmail.com> stability: experimental@@ -24,7 +24,7 @@ Library GHC-Options: -Wall build-depends: base >= 4 && < 4.3- , base-unicode-symbols >= 0.1.1 && < 0.2+ , base-unicode-symbols >= 0.1.1 && < 0.3 , bytestring == 0.9.* , tagged == 0.0.* exposed-modules: System.IO.ExplicitIOModes