PROPOSAL: add tryFdSeek to unix

wren ng thornton wren at
Wed Jun 29 02:15:17 CEST 2011

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

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
        :: (a -> Bool) -> IO a -> IO (Either Errno a)

        :: (a -> Bool) -> IO a -> IO (Either Errno a)

        :: (Num a) => IO a -> IO (Either Errno a)

        :: (Num a) => IO a -> IO (Either Errno a)

        :: IO (Ptr a) -> IO (Either Errno (Ptr a))

        :: IO (Ptr a) -> IO (Either Errno (Ptr a))

        :: (a -> Bool) -> IO a -> IO b -> IO (Either Errno a)

        :: (Num a) => IO a -> IO b -> IO (Either Errno a)

        :: IO (Ptr a) -> IO b -> IO (Either Errno (Ptr a))

        :: (a -> Bool) -> FilePath -> IO a -> IO (Either Errno a)

        :: FilePath -> IO (Ptr a) -> IO (Either Errno (Ptr a))

        :: (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

(2) Instigate discussion about the fate of base:Foreign.C.Error for future

(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 ===

(et seq.)


Live well,

More information about the Libraries mailing list