REQ: add a non-closing version of handleToFd

Florian Weimer fw at
Thu Oct 6 22:50:39 CEST 2011

* Simon Marlow:

> There's another danger.  A Handle has an associated finalizer that
> closes the file descriptor when the Handle is no longer needed by the
> program, so you can't make a handleToFd_noClose because the Handle
> might be closed anyway.

Could you keep a reference to the Handle associated with the FD?  Or
can the auto-closing be moved to the FD, and the Handle could keep
just a reference to it?

> What you can do is make a withHandleFD:
>   withHandleFD :: Handle -> (FD -> IO a) -> IO a
> it's still quite dodgy, depending on what you do with the FD.  Perhaps
> it should be called unsafeWithHandleFD.

And you can't really fix that with monadic regions, either.

Handles (whether called Handle or FD) are the more fundamental
abstraction in the sense that it's more efficient to go from handles
to other abstractions rather than back.

More information about the Glasgow-haskell-users mailing list