Unavailable system functions in `unix` (was: Pull request for inclusion in `unix' module of fsync(2), fdatasync(2), posix_fadvise(2) and posix_fallocate(2))

John Lato jwlato at gmail.com
Sun Dec 22 20:02:16 UTC 2013


On Dec 22, 2013 7:28 AM, "Herbert Valerio Riedel" <hvr at gnu.org> wrote:
>
> On 2013-12-22 at 11:32:20 +0100, Thomas Schilling wrote:
> > Looks like GHC HQ maintains this package.  I don't think it'll make it
> > into the version released with 7.8, though.
>
> fwiw, I've been wanting to review that submission but didn't get to it
> yet;
>
> > I do have another question, though.  How should Haskell code using the
> > `unix` library check for whether `fsync` are implemented or not?
>
> there's a HsUnixConfig.h include file generated (and installed) you can
> include from your Haskell code, and use CPP
>
> > If I call `fsync` I wouldn't want to get a runtime `error` call if the
> > platform doesn't support it.
>
> To be fair, `unix` does not seem consistent with respect to handling
> potentially missing lib/syscalls; I've seen the following three cases:
>
>  a) fallback to implement semantics via different calls
>     (e.g. `System.Posix.Env.unsetEnv`), or
>
>  b) the implementation returns bottom via an `error`-value
>     (e.g. `System.Posix.Temp.mkstemps`), or
>
>  c) the symbol is conditionally exported
>     (e.g. `System.Posix.Directory.tellDirStream`)
>
> > Either I should be able to check at compile time, or I should get a
> > defined exception call which then must be handled by the library.  In
> > either case it should be documented with the function.
>
> It might be worth adding more information to the Haddock-comments
> mentioning the respective `HAVE_*` CPP symbol and whether a
> fallback-implementation is used.
>
> Moreover, the use of `error` to signal non-existing implementations
> could be reconsidered (e.g. maybe switch to a properly thrown
> "call-not-implemented" exception)

This would definitely be better than calling error. Personally I would
prefer conditional exports, as it would turn up errors sooner.

John L.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20131222/ac7c14df/attachment.html>


More information about the Libraries mailing list