openTempFile only defined on GHC

Neil Mitchell ndmitchell at gmail.com
Fri Apr 6 05:55:02 EDT 2007


Hi

> Perhaps as a first step, rather than just omitting them from the export list
> where they aren't supported, they should be replaced by dummy definitions that
> emit a helpful error message?

Like canonicalizeFilePath, which has a dummy implementation
everywhere? It's frustrating to have a standard base library which
isn't standard and portable. I realise that the reason that this was
added was for race-free temporary file creation, but until they are
available on Hugs, my code will use a race-full implementation
everywhere, including GHC.

Could we perhaps have an implementation of this function for all other
compilers:

-- Note: openTempFile is not available on Hugs, which sucks
openTempFileLocal :: FilePath -> String -> IO (FilePath, Handle)
openTempFileLocal dir template = do
    i <- randomRIO (1000::Int,9999)
    let (file,ext) = splitExtension template
        s = dir </> (file ++ show i) <.> ext
    b <- doesFileExist s
    if b then openTempFileLocal dir template else do
        h <- openFile s ReadWriteMode
        return (s, h)

That's what I use everywhere.


> I suspect there are many such examples in the base package, FWIW.  nch98 doesn't
> implement various bits of System.IO.Error, for example.  Hugs has a very
> different version of Control.Concurrent.

I think these should be made very explicit in the documentation.
Control.Concurrent is understandable, things like file creation
methods aren't - a user will be annoyed (and I was) to find that their
program written according to the documentation doesn't work.

Thanks

Neil


More information about the Libraries mailing list