Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
files & handlers...
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2000-02-07 (18:43)
From: Stefan Monnier <monnier+lists/caml/news/@t...>
Subject: Re: files & handlers...
>>>>> "Benoit" == Benoit de Boursetty <> writes:
> And if you write this:
> let f = open_in filename in input_line f;;
> (which is more natural to me)
> you can never close the file you've opened.

> What would the language have to support in order that opened files be
> automatically closed when they get out of reach from the program? Is it
> what is called "finalization"?

Yes, but it should be avoided if possible because of several
restrictions in its semantics.  For most uses a construct such as

	with_file <name>
	  (fn f => <body>)

will work just as well but with the guarantee that the file will be
closed at a well specified time.

	Stefan "obviously not familiar enough with Caml's syntax"