darcs patch: add withFile and withBinaryFile (#966)

David Roundy droundy at darcs.net
Thu Oct 26 12:25:02 EDT 2006


On Thu, Oct 26, 2006 at 08:16:47PM +0400, Bulat Ziganshin wrote:
> Hello David,
> 
> Thursday, October 26, 2006, 8:08:42 PM, you wrote:
> 
> > In case I've been too vague, what I mean is that I'd like it if one could
> > ensure that code such as
> 
> >   withFile "filename" ReadMode return >>= hGetContents
> 
> > statically fails, rather than failing at runtime with a file handle closed
> 
> and how about passing file handle to another thread? ;)

Good point.  I wonder if it would make sense to (not now, but eventually,
in an ideal haskell standard library) give IO a phantom type like ST has,
which by default would refer to the thread involved, and then we could (at
least optionally) open files with a thread-specific handle that can't be
passed to another handle.  Which could also be used to restrict withFile
itself, something like

withFile :: FilePath -> Mode -> (Handle t' -> IO t' ()) -> IO t ()

? Not sure how that would work out with threads, but I'm sure it's
possible...
-- 
David Roundy
Dept. of Physics
Oregon State University


More information about the Libraries mailing list