On Monday 28 January 2008 14:23:01 you wrote:
Jon Harrop wrote:
There are also many features that I would like to steal from other
languages:
. The IDisposable interface from .NET and F#'s "use" bindings.
Is there a reason that Gc.finalise doesn't work?
Absolutely: Gc.finalise is only probabilistic whereas IDisposable is
deterministic. IDisposable guarantees deallocation of resources by a certain
point. (This is why you should never use Gc.finalise alone to manage the
collection of external resources!)
So you write a "use" binding:
let read_first_line file =
use ch = open_in file in
input_line ch
and it gets translated into:
let read_first_line file =
let ch = open_in file in
try input_line ch finally
ch#dispose
What happens when I write: