type 'a res = Ok of 'a | Error of exnlet safe_open_in f file =trylet ic = open_in file inlet r = try Ok (f ic) with e -> Error e inclose_in ic;rwith e -> Error e
Hi,
in Python one can write:
with open("foo") as fd:
fd.write(str)
This involves some language magic that will open the file for the
duration of the block and close it at the end. The file descriptor is
automatically closed at a know time and not leaked or left until the
GC gets around to cleaning it up.
Has anyone constructed something like that for ocaml? Maybe with a ppx
extension?
MfG
Goswin
--
Caml-list mailing list. Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs