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))
Herbert Valerio Riedel
hvr at gnu.org
Sun Dec 22 15:28:29 UTC 2013
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)
More information about the Libraries
mailing list