PROPOSAL: add tryFdSeek to unix

Hello all, I'd like to propose adding a variant of fdSeek which returns errors directly instead of throwing an exception. -- unix:System.Posix.IO tryFdSeek :: Fd -> SeekMode -> FileOffset -> IO (Either Errno FileOffset) The naming convention and desire for non-exceptional versions follows the design of unix-bytestring, which was released as a non-core library for exploring ways to clean up the System.Posix.IO API (since noone was satisfied with the String-based API when adding ByteString variants to unix was proposed[1]). However, this function is more appropriate to add to unix itself, and has been requested by some folks planning to move to unix-bytestring. The proposed implementation is the same as the current implementation of fdSeek, except using eitherErrnoIfMinus1 instead of throwErrnoIfMinus1. Functions like eitherErrnoIfMinus1 can be found here[2] and are straightforward modifications of the exception-throwing variants in Foreign.C.Error. A local copy of eitherErrnoIfMinus1 could be defined in unix, though it makes sense to propose adding it (or eitherErrnoIf) to base instead. While in there, it would be sensible to add eitherErrnoIfRetry as well. For the sake of completeness, the following suite of functions would provide a non exception-throwing variant of the current API: -- base:Foreign.C.Error eitherErrnoIf :: (a -> Bool) -> IO a -> IO (Either Errno a) eitherErrnoIfRetry :: (a -> Bool) -> IO a -> IO (Either Errno a) eitherErrnoIfMinus1 :: (Num a) => IO a -> IO (Either Errno a) eitherErrnoIfMinus1Retry :: (Num a) => IO a -> IO (Either Errno a) eitherErrnoIfNull :: IO (Ptr a) -> IO (Either Errno (Ptr a)) eitherErrnoIfNullRetry :: IO (Ptr a) -> IO (Either Errno (Ptr a)) eitherErrnoIfRetryMayBlock :: (a -> Bool) -> IO a -> IO b -> IO (Either Errno a) eitherErrnoIfMinus1RetryMayBlock :: (Num a) => IO a -> IO b -> IO (Either Errno a) eitherErrnoIfNullRetryMayBlock :: IO (Ptr a) -> IO b -> IO (Either Errno (Ptr a)) eitherErrnoPathIf :: (a -> Bool) -> FilePath -> IO a -> IO (Either Errno a) eitherErrnoPathIfNull :: FilePath -> IO (Ptr a) -> IO (Either Errno (Ptr a)) eitherErrnoPathIfMinus1 :: (Num a) => FilePath -> IO a -> IO (Either Errno a) -- plus all the foo_ variants That's a lot of functions! And most of them are trivial (e.g., all the Minus1, Null, and _ variants). Personally I think the whole suite should be modified into a simple combinator-based approach. However, doing all of that is *not* part of the current proposal === The Proposal === (1) Add tryFdSeek to unix:System.Posix.IO with a local copy of eitherErrnoIfMinus1. (2) Instigate discussion about the fate of base:Foreign.C.Error for future proposals. (3) Tell me where the current unix repo lives so I can make a formal patch. I know a bunch of things were moved from darcs to git recently, but Hackage still reports the darcs repo for unix and I'm not sure if it was one of the ones that moved. Discussion time: 2 weeks. === Links === [1] http://www.haskell.org/pipermail/libraries/2011-February/015970.html (et seq.) [2] http://hackage.haskell.org/packages/archive/unix-bytestring/0.3.4.1/doc/html... -- Live well, ~wren

On Tue, Jun 28, 2011 at 5:15 PM, wren ng thornton
I'd like to propose adding a variant of fdSeek which returns errors directly instead of throwing an exception.
Why wouldn't you just wrap it in Control.Exception.try instead? And what's so special about seeking that suggests that it needs an alternate entry point? (In other words, I'm opposed to this proposal.)

On 29/06/2011 06:44, Bryan O'Sullivan wrote:
On Tue, Jun 28, 2011 at 5:15 PM, wren ng thornton
mailto:wren@freegeek.org> wrote: I'd like to propose adding a variant of fdSeek which returns errors directly instead of throwing an exception.
Why wouldn't you just wrap it in Control.Exception.try instead? And what's so special about seeking that suggests that it needs an alternate entry point?
(In other words, I'm opposed to this proposal.)
Me too. I can imagine that we might want a way to extract an Errno from an IO exception for users of System.Posix who really care about specific Errnos. Cheers, Simon
participants (3)
-
Bryan O'Sullivan
-
Simon Marlow
-
wren ng thornton